-
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
Support for legend with "handles" and "labels" like MATLAB/matplotlib #260
Comments
@liamtoney I'm waiting on some new features from GMT that might make this a lot easier (meaning that we might not have to implement it ourselves). But if it doesn't go through, we should definitely do this. |
Hi @leouieda, it seems like GMT 6 is pretty close to release. Just wanted to ping you for any updates on legend functionality being implemented in the coming release. |
@liamtoney I kind of lost track of this in the main GMT repo (so many things happened in the mean time). I'll start a bit more heavy work on PyGMT soon now that we have 6.0.0rc2 packages for all platforms. I'll get back to this in a little while. Is that OK? |
@leouieda of course! Thanks for all of your hard work. |
Hi @liamtoney, just wondering if you're still willing in implementing this and maybe submit a Pull Request. Quite keen on getting this I can help out with writing some unit tests and bring the code up to date with GMT 6.0.0rc4 if you're short on time, but just thought I'd ask you first 😄 It'll tie in quite nicely with the |
FYI, @PaulWessel is implementing the similar feature on the GMT side. I think it also makes the pygmt legend easier to implement. |
Is that with the auto-legend feature at GenericMappingTools/gmt#1749? |
Yes, I forgot to post the link to the PR. |
@weiji14 I'm happy to help implement this. I don't have any experience writing tests, so I'd definitely appreciate help with that. Should we wait until the dust settles on GMT's auto-legend feature? It might change how I'd approach wrapping the command. |
I actually feel that we can go ahead with wrapping |
Great! Start by creating a pygmt/pygmt/tests/test_colorbar.py Lines 1 to 16 in cbca922
You'll want to replace Once you're happy with the plot, create a 'baseline' output plot using:
After that, test your code by running |
Thanks, I will try to wrap up the legend implementation on the C side in the next 1-2 days. |
A legend function is something I've been looking for of late. I'm more than happy to help test any of the implementations mentioned above when they become available. |
@weiji14 do I need to build rc4 from source to do dev stuff? I tried
into the EDIT I have 6.0.0rc2 on my machine , built from source a while ago. I did the hack required_version = "6.0.0rc2" in |
@weiji14 here's my try at a test for the legend. It passes. I'm not sure what sort of tests are good to write, so I'd appreciate some guidance on that. I also should re-visit the actual legend implementation. https://github.com/liamtoney/pygmt/commit/cddf2cf18b5a12e2ec7fa1650f218b01267317a6 Let me know at what point it makes sense to make a PR out of this. |
The test looks a bit long, but it's a good start! We tend to want tests that test one specific 'unit' of functionality, for e.g. positioning of the legend, changing the colour of the border, etc. Also you might want to make sure that passing in a You can actually submit a PR right now, and put 'WIP' in the title (call if `WIP Wrap legend', that'll make it easier for me or anyone else on the team to help you out by making 'suggested changes'. |
Gotcha on the unit test thing. I'll make some of those later this week if I have time.
Done. We can use that thread for further conversation if you want. |
P.S. If you'd like to understand testing a bit more, I highly recommend Automation Panda's Python Testing 101 series. In particular, the introduction and pytest one will be relevant for PyGMT. He's also got some videos if you prefer that style of learning. |
Description of the desired feature
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.Below is a minimal working example using my
add-legend
fork:Are you willing to help implement and maintain this feature?
Yes. You can view the source code for my implementation here.
The good news:
gmt.Figure.plot()
is that it now returnskwargs
. So existing users won't have to change their syntax for the plot command.The bad news:
GMTTempFile
since I don't know how to do it any other way (yet).re
) to separate symbol type and size from thestyle
argument ofgmt.Figure.plot()
, which is probably really sketchy.S - symbol size fill pen - text
I feel like this covers a broad portion of typical legend use cases, though.
The text was updated successfully, but these errors were encountered: