-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable -l<label> auto-legend in plot #1749
Conversation
When plotting plain symbols with known size and color/pen we can automatically build a legend file via -l in plot. Only applies to modern mode. Not documented yet.
If only lines are plotted with no symbol size then default to 0.5 cm.
I think the plot/legend auto-labeling is simple enough to add to 6.0.0 even if a new feature. Here is an example script that plots a table three times with lines and different symbols and using the -llabel option to build up an automatic label info file. Since legend is not given a legend file it looks to see if there is a hidden one. I implemented this the same way we do CPT so there may be one legend per scope (figure, subplot, etc):
which gives this plot: What do you think, @GenericMappingTools/core? There are a few unresolved issues: While the given symbol sizes are used to build the legend, a line is not specified with a size in plot. I assign lines the same symbol size as the max symbol size given to other items n the legend. If there are only lines then I default to 0.5 cm. |
Enable vertical lines, gaps, and font selection.
Must match uppercase codes in pslegend. Also add to cookbook.
Add doc script showing autolegend and add to cookbook.
Update: I have completed the implementation of -l. There are modifier support for drawing horizontal (+d) and vertical (+v) lines, add a gap (+g), change the number of columns (+n), and set a header (+h). You will note these lower-case modifiers correspond to the upper-case legend codes in pslegend. In addition there is a way to specify the font (+f) and override the symbol size (or set line length) via +s. Documentation has been updated, new test and doc script added. What remains is to use this in a few of our gallery examples. |
These were perfect examples of using -l to generate legend data. Slight differences required an update to the two PS files.
We need also a flag to positioning the legend in the figure. |
That is what legend does, at the end. |
I am guessing you mean one should not have to call legend at the end? We could contemplate that with some basic defaults. But I dont think we want to replicate all the options in gmt legend that pertains to placement, width, justification, outline, shade, line-spacing, etc. etc. We might be able to guesstimate a suitable legend box width from the strings, then slap a white box in the TR corner. |
Yes. Once -l is used it's clear that a legend is required. So if |
Probably should be +jjust [TR]. So this means gmt end, as it loops over all the figures, need to check if there is a legend file for that scope and that it has not yet been used for this figure. if so, it needs to guesstimate a width from the longest text label plus space for symbol and gaps, get the +jjust setting from a comment in the legend file, and then call legend, maybe with some small offset from the toner via +o, maybe 1-2 % of map dimensions? |
Well, it is more complicated: When an inset or a subplot panel calls inset end or subplot end, we need to do the same thing: was there a legend file created that was not used, and if so call gmt legend here as well. Then for all figures as well. The legend spec files can appear for insets, subplot panels, figures, and session (one figure). |
Now, when legend is called and there is no input file and a hidden legend file is found, we use it and then delete it. THus, when gmt inset end, gmt subplot end, or gmt end come along and find a legend file it means legend was not called explicitly. If so, we add a call to legend with a few default settings.
I gotta go teach etc but I have added support for automatically plotting the legend if no legend call is made and a legend file is found (because of -l options). I tested the case above which works. it would be great if someone could make examples like the above with subplots and insets so that I can test if they work as well [not tested so far]. |
Must check for auto-legend when subplot end comes.
…gTools/gmt into activateautolegend
Never mind, the subplot works fine. |
Looks like things are working. Please try to break it. Subplot:
Inset:
|
Not about the legend, but shouldn't the inset E & N annotations be trimmed? |
-l+s changes size, but it's a constant size, whilst the symbols in the plot may have different sizes. |
Your first question is I was lazy and did not add margin space with -M. Second question is good, maybe we want it to be an overall scaling instead of a fixed size. The problem I was trying to solve was the "size" of lines which are undefined. So we could say if size is zero (line) then set to this size, else if size is > 0 then scale. |
But your first also begs the question if gmt inset begin should turn on a clip path, to be undone when gmt inset ends comes along. Should it? |
Or should gmt inset begin have option -C for clip on [off]? |
Or reverse (like pstext), have -N for no clip [clip]? |
|
|
When plotting large symbols, we usually need a larger line-spacing (i.e.
|
It seems there are two ways to set the length of a line. What's the difference? |
Hm, yes I guess we could eliminate +l. This has gone back and forth... OK, will stick with +s to set a fixed dimension of a symbol, including a line segment length. |
Please also see my comments above. We may use
|
Regarding larger line spacing: The actual line spacing is determined by two times: the current annotation font and the line scaling [1.1]. Normally, if you really wanted to do large symbols bigger than your annotation font you would either change the font (you may be making a large wall map so that makes sense) or you mess with +lspacing in pslegend. We could add +lspacing for this since the current line length can be absorbed by +s. However, pretty sure we will get calls for adding +wwidth too since the auto-width cannot be perfect until I code all that up in PostScript itself. I think we will need to do that at some point. The only time one would need to specify a width is when setting paragraphs since they need to wrap at the end of the line. So legend -D...+w can probably never go away but can be optional for the cases without a paragraph of text (most cases). Same with -l. So we will need +w as well for now since I cannot compute a proper width that will work for any font. |
Line length is now set by +s as for other symbols. Legend width can be hard-wired via +w.
I removed +l (for now) so line length is also set with +s. I added +w to set legend width. That is the only cure for your short legend labels above. Try adding +w1.6c to your "A" label option. |
|
Did not make it into the legends file.
Did not actually use +n to scale the width - now does. But only if +n is given on the first -l. If used later it simply sub-divides the available space set at the start. |
It's a little misleading here. I though it sets the font of "H headers" and "regular label strings". |
We normally don't those to have the same font size, so hardly the same flag. |
I will clarify what +f does in the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-l
looks good to me.
I think perhaps we should add a beta warning in the -l instructions since this is so fresh that we may wish to break some compatibility as we learn more of its use? |
When plotting plain symbols with known size and color/pen we can automatically build a legend file via -l[label] in plot. Only applies to modern mode. Not documented yet. May or may not go into 6.0 or master but seems straightforward.