cartopy.mpl.ticker.LatitudeFormatter#

class cartopy.mpl.ticker.LatitudeFormatter(direction_label=True, 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)[源代码]#

基类:_PlateCarreeFormatter

纬度轴的勾选格式器。

纬度的勾选格式器。

当绑定到轴时,该轴必须是矩形投影上定义的轴的一部分(例如Plate Carree、Mercator)。

参数:
  • direction_label (optional) -- 如果 True 将在纬度标签旁边绘制方向标签(N或S)。如果 False 那么这些标签就不会被画出来。默认为 True (draw方向标签)。

  • degree_symbol (optional) -- 用于表示刻度标签中的度数符号的字符。默认为“°”。如果不需要程度符号,则可以是空字符串。

  • number_format (optional) -- 格式字符串以表示经度值时 dms 设置为False。默认为“g”。

  • transform_precision (optional) -- 设置转换后的刻度值的舍入精度(以度为单位)。默认值是1 e-7,应该适合大多数用例。若要控制记号标签的外观,请使用 number_format 关键字

  • dms (bool, optional) -- 是否格式为度-分-秒而不是小数度。

  • minute_symbol (str, optional) -- 用于表示分钟符号的字符。

  • second_symbol (str, optional) -- 用于表示第二个符号的字符。

  • seconds_number_format (optional) -- 格式化字符串以表示经度值的“秒”分量。默认为“g”。

  • auto_hide (bool, optional) -- 冗余时自动隐藏度数或分钟数。

  • decimal_point (bool, optional) -- 小数点性格。如果没有提供并且 mpl.rcParams['axes.formatter.use_locale'] == True ,则使用区域设置小数点。

  • cardinal_labels (dict, optional) -- 带有“south”和/或“north”键的字典,用于替换南和北基本标签,默认为“S”和“N”。

备注

格式器只能用于一个轴。必须为每个需要格式化标签的轴创建新的格式器。

示例

在Plate Carree投影上标记-90到90的纬度:

ax = plt.axes(projection=PlateCarree())
ax.set_global()
ax.set_yticks([-90, -60, -30, 0, 30, 60, 90],
              crs=ccrs.PlateCarree())
lat_formatter = LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)

在墨卡托投影上标记-80到80的纬度,这次省略度数符号::

ax = plt.axes(projection=Mercator())
ax.set_global()
ax.set_yticks([-90, -60, -30, 0, 30, 60, 90],
              crs=ccrs.PlateCarree())
lat_formatter = LatitudeFormatter(degree_symbol='')
ax.yaxis.set_major_formatter(lat_formatter)

当未绑定到轴时:

lat_formatter = LatitudeFormatter()
ticks = [-90, -60, -30, 0, 30, 60, 90]
lat_formatter.set_locs(ticks)
labels = [lat_formatter(value) for value in ticks]