-
Notifications
You must be signed in to change notification settings - Fork 224
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
Wrap legend #333
Wrap legend #333
Conversation
Basic first implementation of legend wrapper.
First try at a MATLAB/matplotlib-style legend syntax. Not tested extensively for obscure symbol styles.
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.
Hi @liamtoney, just checking in on how you're doing. If you're stuck with finding a specfile, maybe try to pull in the @Table_5_11.txt
dataset. You can look at GenericMappingTools/gmt#1749 (comment) for some inspiration (though the auto-legend won't work yet).
I also see that pylint is complaining a lot so I've suggested a few changes. Run make lint
to see what the other problems are, and try your best to resolve those. If it's too hard, we can try to resolve them for you or teach you how to set an ignore flag (if it proves to be impossible).
The auto-legend feature has been merged into GMT 6.0 branch in GenericMappingTools/gmt#1749. Now we can use
With the auto-legend feature merged, it's almost straightforward to wrap the legend module in pygmt, and we can write a Python script like:
The only problem is, GMT 6.0.0 is not official released yet. It shouldn't take too long. We plan to release GMT 6.0.0 when the GMT6 paper is officially published. |
Great. This should simplify the wrapper a lot. From a dev perspective, to build and test this wrapper do I now need to clone the GMT repo and build from source? Or are there plans for another conda release? |
We're still using 6.0.0rc4 for pygmt development, and that's what our code is tested against. I think we should wrap this up and refactor the code after 6.0.0 stable is released. The implementation doesn't have to be perfect, having something is better than nothing! |
FYI, the GMT team is planing to release 6.0.0rc5 (with the auto-legend feature included) next week, and release the final 6.0.0 on Nov. 1. |
Right, it's not quite as easy as it seems... The auto-legend only gets triggered when we run
Produces: I'm assuming though that calling |
I think you're right. With pygmt, we have to call |
So could the code have an empty legend call after plotting, e.g. import pygmt
fig = pygmt.Figure()
fig.basemap(projection="x1i", region="0/7/3/7", frame=True)
fig.plot(data="@Table_5_11.txt", style="c0.15i", color="lightgreen", pen="faint", l="Apples")
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", l="My_lines")
fig.plot(data="@Table_5_11.txt", style="t0.15i", color="orange", l="Oranges")
fig.legend() # Empty legend call
fig.show() where |
Hmm, I just tried using an empty |
Ah wait, I just noticed a new Edit: Argh! Even with |
Now it tests the `position` argument
Oops, sorry, hit the close button by accident... I was thinking the same thing. The thing is, GMT does have a default position setting that gets triggered by calling end, and we would be 'reinventing the wheel' a bit here. |
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.
Right, just a couple of minor edits to the test file (you're almost there!). Plus you'll need to add a line to the docs/api/index.rst
file so that your shiny legend
shows up in the docs! Do it like so:
Figure.grdimage
Figure.legend
Figure.logo
Once you're done, remove the "WIP" from the title and it should be good to go 🚀. Let's open up a separate pull request to get that default position
feature into PyGMT since this one is already getting way too long.
@weiji14 I've made those changes. My commit history is a little messy (sorry) — does anything need to be done about that prior to merging? |
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.
Hi @liamtoney, just one last change! And no you don't have to worry about the commit history since we'll be squash merging (i.e. it'll only show up as a single commit on the master branch).
Co-Authored-By: Wei Ji <[email protected]>
Thanks for walking me through this, @weiji14! |
Phew, good work @liamtoney. Thanks for having the stamina to see this one through! Feel free to open up another pull request to get the auto-position done (and we can debate around the implementation 😆). Also it'd be great to have a gallery example for |
@@ -181,6 +181,8 @@ def grdcontour(self, grid, **kwargs): | |||
Do not draw contours with less than `cut` number of points. | |||
S : string or int | |||
Resample smoothing factor. | |||
l : str |
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.
grdcontour doesn't support -l
option now. Currently only plot
supports auto-label.
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.
Resolving in #357.
Oops, that's my bad 🤦♂️. I'll fix that. |
Description of proposed changes
A wrapper for the GMT 6
legend
command with support for specifying "handles" and "labels" as arguments, as in MATLAB (legend docs) and matplotlib (legend docs). The plotting commands (i.e.,gmt.Figure.plot()
, for now) are modified to return "handles" which are provided as inputs togmt.Figure.legend()
. This addresses part of #214 and #231.Fixes #260
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.