pygmt.Figure.legend

Figure.legend(spec=None, position='JTR+jTR+o0.2c', box='+gwhite+p1p', **kwargs)

Plot legends on maps.

Makes legends that can be overlaid on maps. Reads specific legend-related information from an input file, or automatically creates legend entries from plotted symbols that have labels. Unless otherwise noted, annotations will be made using the primary annotation font and size in effect (i.e., FONT_ANNOT_PRIMARY).

Full option list at https://docs.generic-mapping-tools.org/latest/legend.html

Aliases:

  • D = position

  • F = box

  • J = projection

  • R = region

Parameters
  • spec (None or str or io.StringIO) – Set to None (default) for using the automatically generated legend specification file. Alternatively, pass in a filename or an io.StringIO in-memory stream buffer pointing to the legend specification text.

  • projection (str) – Required if this is the first plot command. Select map projection.

  • region (str or list) – Required if this is the first plot command. 'xmin/xmax/ymin/ymax[+r][+uunit]'. Specify the region of interest.

  • position (str) – '[g|j|J|n|x]refpoint+wwidth[/height][+jjustify][+lspacing] [+odx[/dy]]' Defines the reference point on the map for the legend. By default, uses ‘JTR+jTR+o0.2c’ which places the legend at the top-right corner inside the map frame, with a 0.2 cm offset.

  • box (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. By default, uses ‘+gwhite+p1p’ which draws a box around the legend using a 1 point black pen and adds a white background.