-
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
Merged
Merged
Wrap legend #333
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e708414
Add Figure.legend() wrapper
liamtoney 60f1b73
Implement handles/labels functionality for Figure.legend()
liamtoney 03fbff8
Merge branch 'master' of https://github.com/GenericMappingTools/gmt-p…
liamtoney 8a19632
Merge branch 'master' of https://github.com/GenericMappingTools/gmt-p…
liamtoney 826318e
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt…
liamtoney ae6335b
Merge with pygmt master
liamtoney a6771a1
Use extlinks for legend docstring
liamtoney 69f327e
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt…
liamtoney 95d170d
Hack to allow rc2
liamtoney cddf2cf
Add test for legend
liamtoney a57dec3
Revert "Hack to allow rc2"
liamtoney 2ddec23
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt…
liamtoney da4569c
Use aliases for D and F args
liamtoney 1b07abb
Simplify data_kind() call
liamtoney 88addf7
Flesh out documentation
liamtoney 24330cd
Merge branch 'master' of https://github.com/GenericMappingTools/pygmt…
liamtoney 3a18c63
Alias label (l) for plot
weiji14 c628f27
Merge pull request #1 from weiji14/plot/alias_label
liamtoney 391e710
Merge branch 'master' into add-legend
liamtoney a514b59
Use GMT's auto-legend feature instead of regex
liamtoney 519e383
Remove unused GMTTempFile import
liamtoney 9130f47
Revise first legend test
liamtoney 52ae8ee
Add legend entries test
liamtoney 58dba31
Add legend specfile test
liamtoney f44e98e
Add failing test
liamtoney e737ca8
Add legend to index.rst
liamtoney 557149d
Remove unneeded decorator
liamtoney 850a96a
Merge branch 'master' into add-legend
weiji14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
""" | ||
Tests for legend | ||
""" | ||
import pytest | ||
|
||
from .. import Figure | ||
from ..exceptions import GMTInvalidInput | ||
from ..helpers import GMTTempFile | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_legend_position(): | ||
""" | ||
Try positioning with each of the four legend coordinate systems. | ||
""" | ||
|
||
fig = Figure() | ||
|
||
fig.basemap(region=[-2, 2, -2, 2], frame=True) | ||
|
||
positions = ["jTR+jTR", "g0/1", "n0.2/0.2", "x4i/2i/2i"] | ||
|
||
for i, position in enumerate(positions): | ||
|
||
fig.plot(x=[0], y=[0], style="p10p", label=i) | ||
fig.legend(position=position, box=True) | ||
|
||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_legend_entries(): | ||
""" | ||
Test different marker types/shapes. | ||
""" | ||
|
||
fig = 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(position="JTR+jTR") | ||
|
||
return fig | ||
|
||
|
||
@pytest.mark.mpl_image_compare | ||
def test_legend_specfile(): | ||
""" | ||
Test specfile functionality. | ||
""" | ||
|
||
specfile_contents = """ | ||
G -0.1i | ||
H 24 Times-Roman My Map Legend | ||
D 0.2i 1p | ||
N 2 | ||
V 0 1p | ||
S 0.1i c 0.15i p300/12 0.25p 0.3i This circle is hachured | ||
S 0.1i e 0.15i yellow 0.25p 0.3i This ellipse is yellow | ||
S 0.1i w 0.15i green 0.25p 0.3i This wedge is green | ||
S 0.1i f0.1i+l+t 0.25i blue 0.25p 0.3i This is a fault | ||
S 0.1i - 0.15i - 0.25p,- 0.3i A dashed contour | ||
S 0.1i v0.1i+a40+e 0.25i magenta 0.25p 0.3i This is a vector | ||
S 0.1i i 0.15i cyan 0.25p 0.3i This triangle is boring | ||
V 0 1p | ||
D 0.2i 1p | ||
N 1 | ||
G 0.05i | ||
G 0.05i | ||
G 0.05i | ||
L 9 4 R Smith et al., @%5%J. Geophys. Res., 99@%%, 2000 | ||
G 0.1i | ||
P | ||
T Let us just try some simple text that can go on a few lines. | ||
T There is no easy way to predetermine how many lines will be required, | ||
T so we may have to adjust the box height to get the right size box. | ||
""" | ||
|
||
with GMTTempFile() as specfile: | ||
|
||
with open(specfile.name, "w") as file: | ||
file.write(specfile_contents) | ||
|
||
fig = Figure() | ||
|
||
fig.basemap(projection="x6i", region=[0, 1, 0, 1], frame=True) | ||
fig.legend(specfile.name, position="JTM+jCM+w5i") | ||
|
||
return fig | ||
weiji14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_legend_fails(): | ||
""" | ||
Test legend fails with invalid spec | ||
""" | ||
fig = Figure() | ||
with pytest.raises(GMTInvalidInput): | ||
fig.legend(spec=["@Table_5_11.txt"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 onlyplot
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.