Skip to content
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

Implement default position/box for legend #359

Merged
merged 6 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pygmt/base_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def image(self, imagefile, **kwargs):
@fmt_docstring
@use_alias(R="region", J="projection", D="position", F="box")
@kwargs_to_strings(R="sequence")
def legend(self, spec=None, **kwargs):
def legend(self, spec=None, position="JTR+jTR", **kwargs):
liamtoney marked this conversation as resolved.
Show resolved Hide resolved
"""
Plot legends on maps.

Expand All @@ -644,13 +644,18 @@ def legend(self, spec=None, **kwargs):
{R}
position (D) : str
``'[g|j|J|n|x]refpoint+wwidth[/height][+jjustify][+lspacing][+odx[/dy]]'``
Defines the reference point on the map for the legend.
Defines the reference point on the map for the legend. By default, uses
'JTR+jTR' which places the legend in the upper-right corner, inside.
liamtoney marked this conversation as resolved.
Show resolved Hide resolved
box (F) : bool or str
``'[+cclearances][+gfill][+i[[gap/]pen]][+p[pen]][+r[radius]][+s[[dx/dy/][shade]]]'``
Without further options, draws a rectangular border around the
legend using **MAP_FRAME_PEN**.
"""
kwargs = self._preprocess(**kwargs)

if "D" not in kwargs:
kwargs["D"] = position
weiji14 marked this conversation as resolved.
Show resolved Hide resolved

with Session() as lib:
if spec is None:
specfile = ""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions pygmt/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ def test_legend_position():
return fig


@pytest.mark.mpl_image_compare
def test_legend_default_position():
"""
Try using the default legend position.
"""

fig = Figure()

fig.basemap(region=[-1, 1, -1, 1], frame=True)

fig.plot(x=[0], y=[0], style="p10p", label="Default")
fig.legend()

return fig


@pytest.mark.mpl_image_compare
def test_legend_entries():
"""
Expand Down