Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This reverts commit 95d170d.
Co-Authored-By: Wei Ji <23487320+weiji14@users.noreply.github.com>
weiji14
left a comment
There was a problem hiding this comment.
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).
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
seisman
commented
Oct 12, 2019
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. |
liamtoney
commented
Oct 15, 2019
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? |
weiji14
commented
Oct 16, 2019
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! |
seisman
commented
Oct 16, 2019
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 |
seisman
commented
Oct 24, 2019
I think you're right. With pygmt, we have to call |
liamtoney
commented
Oct 24, 2019
So could the code have an empty legend call after plotting, e.g. importpygmtfig=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 callfig.show()where |
weiji14
commented
Oct 24, 2019
Hmm, I just tried using an empty |
Ah wait, I just noticed a new Edit: Argh! Even with |
Now it tests the `position` argument
liamtoney
commented
Oct 29, 2019
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
liamtoney
commented
Oct 31, 2019
@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? |
weiji14
left a comment
There was a problem hiding this comment.
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).
Uh oh!
There was an error while loading. Please reload this page.
Co-Authored-By: Wei Ji <23487320+weiji14@users.noreply.github.com>
liamtoney
commented
Oct 31, 2019
Thanks for walking me through this, @weiji14! |
weiji14
commented
Oct 31, 2019
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 |
| 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.
grdcontour doesn't support -l option now. Currently only plot supports auto-label.
weiji14
commented
Oct 31, 2019
Oops, that's my bad 🤦♂️. I'll fix that. |


Description of proposed changes
A wrapper for the GMT 6
legendcommand 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 formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.