add_gridlines

Maps.add_gridlines(d=None, auto_n=10, n=100, bounds=None, layer=None, *, m=None, labels=False, dynamic=False, **kwargs)

Add gridlines to the map.

By default, an appropriate grid-spacing is determined via the β€œauto_n” kwarg.

An explicit grid-spacing can be used by providing the grid-separation via the β€œd” kwarg.

Parameters:
  • d (int, float, 2-tuple, list, numpy.array or None) –

    Set the location of the gridlines (for a fixed grid).

    • For a regular grid with a fixed spacing, provide a number or a tuple of numbers to set the lon/lat distance between the grid-lines.

      >>> d = 10       # a regular 10 degree grid
      >>> d = (5, 10)  # a regular grid with d_lon=5 and d_lat=10
      
    • To draw only specific gridlines, provide a tuple of lists or numpy-arrays of (lon, lat) values.

      >>> d = ([lon0, lon1, lon2, ...], [lat0, lat1, ...])
      
    • If d = None, gridlines are automatically determined based on the β€œauto_n” parameter.

    The default is None

  • auto_n (int or 2-tuple) – Only relevant if β€œd” is None! The (rough) number of gridlines to use when evaluating the automatic grid-spacing. To use different numbers of gridlines in each direction, provide a tuple of ints, e.g.: (n_lon, n_lat). The default is 10.

  • layer (str) – The name of the layer on which the gridlines should be visible.

  • bounds (4-tuple) – A tuple of boundaries to limit the gridlines to a given extent. (lon_min, lon_max, lat_min, lat_max) The default is None in which case (-180, 180, -90, 90) is used.

  • n (int) – The number of intermediate points to draw for each line. (e.g. to nicely draw curved grid lines) The default is 100

  • labels (bool or dict, optional) –

    If True, add grid-labels to the map. If a dict is provided, it is passed to GridLines.add_labels().

    This is a shortcut for using:

    >>> g = m.add_gridlines()
    >>> g.add_labels(fontsize=7, color="b", ...)
    

    The default is False.

  • kwargs –

    Additional kwargs passed to matplotlib.collections.LineCollection.

    The default is: (ec=”0.2”, lw=0.5, zorder=100)

Returns:

g – The GridLines-object.

Return type:

GridLines

Note

To add labels to the grid, use:

>>> g = m.add_gridlines(...)
>>> g.add_labels(...)

Examples

>>> m = Maps(Maps.CRS.InterruptedGoodeHomolosine())
>>> m.add_feature.preset.ocean()
>>> g0 = m.add_gridlines(d=10, ec=".5", lw=0.25, zorder=1, layer="g")
>>> g1 = m.add_gridlines(d=(10, 20), ec="k", lw=0.5, zorder=2, layer="g")
>>> g2 = m.add_gridlines(d=5, ec="darkred", lw=0.25, zorder=0,
>>>                      bounds=(-20, 40, -20, 60), layer="g")
>>> m.show_layer(m.layer, "g")