File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
examples/tutorials/basics Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1010"""
1111
1212# %%
13+ import io
14+
1315import pygmt
1416
1517# %%
4951# array to the ``size`` parameter. Because the magnitude is on a logarithmic
5052# scale, it helps to show the differences by scaling the values using a power
5153# law.
54+ #
55+ # A legend for the size of the circles can not be added automatically. But users can
56+ # create an :class:`io.StringIO` object, which can be passed to the ``spec`` parameter
57+ # of :meth:`pygmt.Figure.legend`. For details on creating legends, see the tutorial
58+ # :doc:`multiple-column legend </tutorials/advanced/legends>`.
5259
5360fig = pygmt .Figure ()
5461fig .basemap (region = region , projection = "M15c" , frame = True )
6168 fill = "white" ,
6269 pen = "black" ,
6370)
71+ legend = io .StringIO (
72+ "\n " .join (f"S 0.4 c { 0.02 * 2 ** m :.2f} - 1p 1 Mw { m } " for m in [3 , 4 , 5 ])
73+ )
74+ fig .legend (spec = legend , position = "jBR+o0.2c+l2" , box = True )
6475fig .show ()
6576
6677# %%
7586# the earthquakes using :func:`pygmt.makecpt`, then set ``cmap=True`` in
7687# :meth:`pygmt.Figure.plot` to use the colormap. At the end of the plot, we
7788# also plot a colorbar showing the colormap used in the plot.
78- #
7989
8090fig = pygmt .Figure ()
8191fig .basemap (region = region , projection = "M15c" , frame = True )
91101 pen = "black" ,
92102)
93103fig .colorbar (frame = "xaf+lDepth (km)" )
104+ fig .legend (spec = legend , position = "jBR+o0.2c+l2" , box = True )
94105fig .show ()
95106
96107# sphinx_gallery_thumbnail_number = 3
You can’t perform that action at this time.
0 commit comments