add_labels

GridLines.add_labels(where='tblr', offset=10, precision=2, every=None, exclude='corners', labels=None, rotation=0, rotation_relative=True, **kwargs)

Add labels to the gridlines.

Parameters:
  • where (str or int, optional) –

    Specify where labels should be added to the gridlines.

    In general, the position of labels is determined by the intersection-points of the gridlines with the axis-boundary.

    To select specific labels, use one of the following options:

    • Use a combination of the letters β€œtblr” (top, bottom, left, right) to draw labels only at the selected sides of the plot. (NOTE: With this option, latitude-lines are labeled only on β€œl” and β€œr”, and longitude-lines are labeled only on β€œt” and β€œb”!)

    • Use β€œall” to add all labels without any restrictions

    • Use an integer to add labels only to the nth found intersection point (e.g. 0 for the first intersection-point, 1 for the second etc.)

    The default is β€œtblr”.

  • offset (number or tuple of numbers, optional) –

    The offset of the labels relative to the intersection point of the gridline with the axes-boundary.

    • number (d): the offset in the direction of of the rotation of the label.

    • 2-tuple (x, y): the offset in x- and y- direction.

    • 3-tuple (d, x, y): all of the above

    The default is 10.

  • precision (int, optional) – The floating point precision of the labels. The default is 2.

  • every (int, slice, tuple or None, optional) –

    Specify if all labels (None) or only every nth label should be drawn.

    • if int: draw every nth label

    • if 3-tuple: draw every nth label according to (start, stop, step) (use stop=-1 if you want to draw all labels)

    The default is None.

  • exclude (str, list, tuple or None, optional) –

    Exclude one (or more) labels.

    • A list of grid values to exclude as lon/lat labels. (e.g. [10, -45])

    • Provide a tuple of lists to exclude lon/lat values separately (e.g. ([-120, 60], [-40, 40])).

    • If β€œcorners”, the corner-points of the boundaries are excluded (this is the default to avoid overlapping lon/lat labels at the corners).

    • If None, no points are excluded.

    The default is β€œcorners”.

  • labels (list or None, optional) – A list of strings to use as custom labels. If None, the grid-values are used. The default is None.

  • rotation (float, optional) – The rotation of the label. The default is 0.

  • rotation_relative (bool, optional) – Indicator if the rotation is performed relative to the current label-rotation (True) or the rotation is set to the provided value (False). The default is True.

  • kwargs – Additional kwargs passed to matplotlib’s plt.text(…) for additional styling of the labels. (e.g. fontsize, fontweight, color, …)

Returns:

gl – The class that handles the drawing of the grid-labels.

Return type:

GridLabels