Skip to content

Commit 4a511a9

Browse files
Figure.legend: Add an inline example (#4930)
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
1 parent cf6775e commit 4a511a9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎pygmt/src/legend.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from pygmt.params import Axis, Box, Frame, Position
1515
from pygmt.src._common import _parse_position
1616

17+
__doctest__skip__ = ["legend"]
18+
1719

1820
@fmt_docstring
1921
def legend(
@@ -115,6 +117,23 @@ def legend(
115117
$panel
116118
$perspective
117119
$transparency
120+
121+
Examples
122+
--------
123+
Create a legend automatically from the plotted symbols and lines that have labels:
124+
125+
>>> import pygmt
126+
>>> from pygmt.params import Box, Position
127+
>>> fig = pygmt.Figure()
128+
>>> fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
129+
>>> fig.plot(x=[2, 5, 8], y=[3, 6, 4], style="c0.3c", fill="red", label="Circles")
130+
>>> fig.plot(x=[2, 5, 8], y=[7, 2, 8], pen="1p,blue", label="Line")
131+
>>> fig.legend(
132+
... position=Position("BL", offset=0.2),
133+
... width="4c",
134+
... box=Box(pen="1p,gray30", fill="lightyellow", radius="4p"),
135+
... )
136+
>>> fig.show()
118137
"""
119138
# Set default box if both position and box are not given.
120139
# The default position will be set later in _parse_position().

0 commit comments

Comments
 (0)