cartopy.mpl.ticker.LongitudeFormatter#

class cartopy.mpl.ticker.LongitudeFormatter(direction_label=True, zero_direction_label=False, dateline_direction_label=False, degree_symbol='°', number_format='g', transform_precision=1e-08, dms=False, minute_symbol='′', second_symbol='″', seconds_number_format='g', auto_hide=True, decimal_point=None, cardinal_labels=None)[source]#

Bases: _PlateCarreeFormatter

Tick formatter for a longitude axis.

Create a formatter for longitudes.

When bound to an axis, the axis must be part of an axes defined on a rectangular projection (e.g. Plate Carree, Mercator).

Parameters:
  • direction_label (optional) – If True a direction label (E or W) will be drawn next to longitude labels. If False then these labels will not be drawn. Defaults to True (draw direction labels).

  • zero_direction_label (optional) – If True a direction label (E or W) will be drawn next to longitude labels with the value 0. If False then these labels will not be drawn. Defaults to False (no direction labels).

  • dateline_direction_label (optional) – If True a direction label (E or W) will be drawn next to longitude labels with the value 180. If False then these labels will not be drawn. Defaults to False (no direction labels).

  • degree_symbol (optional) – The symbol used to represent degrees. Defaults to ‘°’.

  • number_format (optional) – Format string to represent the latitude values when dms is set to False. Defaults to ‘g’.

  • transform_precision (optional) – Sets the precision (in degrees) to which transformed tick values are rounded. The default is 1e-7, and should be suitable for most use cases. To control the appearance of tick labels use the number_format keyword.

  • dms (bool, optional) – Whether or not formatting as degrees-minutes-seconds and not as decimal degrees.

  • minute_symbol (str, optional) – The character(s) used to represent the minute symbol.

  • second_symbol (str, optional) – The character(s) used to represent the second symbol.

  • seconds_number_format (optional) – Format string to represent the “seconds” component of the latitude values. Defaults to ‘g’.

  • auto_hide (bool, optional) – Auto-hide degrees or minutes when redundant.

  • decimal_point (bool, optional) – Decimal point character. If not provided and mpl.rcParams['axes.formatter.use_locale'] == True, the locale decimal point is used.

  • cardinal_labels (dict, optional) – A dictionary with “west” and/or “east” keys to replace west and east cardinal labels, which defaults to “W” and “E”.

Note

A formatter can only be used for one axis. A new formatter must be created for every axis that needs formatted labels.

Examples

Label longitudes from -180 to 180 on a Plate Carree projection with a central longitude of 0:

ax = plt.axes(projection=PlateCarree())
ax.set_global()
ax.set_xticks([-180, -120, -60, 0, 60, 120, 180],
              crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)

Label longitudes from 0 to 360 on a Plate Carree projection with a central longitude of 180:

ax = plt.axes(projection=PlateCarree(central_longitude=180))
ax.set_global()
ax.set_xticks([0, 60, 120, 180, 240, 300, 360],
              crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)

When not bound to an axis:

lon_formatter = LongitudeFormatter()
ticks = [0, 60, 120, 180, 240, 300, 360]
lon_formatter.set_locs(ticks)
labels = [lon_formatter(value) for value in ticks]
set_locs(locs)[source]#

Set the locations of the ticks.

This method is called before computing the tick labels because some formatters need to know all tick locations to do so.