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)[源代码]#
基类:
_PlateCarreeFormatter
经度轴的勾选格式器。
为格式创建格式器。
当绑定到轴时,该轴必须是矩形投影上定义的轴的一部分(例如Plate Carree、Mercator)。
- 参数:
direction_label (optional) -- 如果 True 将在经度标签旁边绘制方向标签(E或W)。如果 False 那么这些标签就不会被画出来。默认为 True (draw方向标签)。
zero_direction_label (optional) -- 如果 True 方向标签(E或W)将被绘制在值为0的经度标签旁边。如果 False 那么这些标签就不会被画出来。默认为 False (no方向标签)。
dateline_direction_label (optional) -- 如果 True 将在值为180的经度标签旁边绘制方向标签(E或W)。如果 False 那么这些标签就不会被画出来。默认为 False (no方向标签)。
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) -- 带有“west”和/或“east”键的字典,用于替换west和East基本标签,默认为“W”和“E”。
备注
格式器只能用于一个轴。必须为每个需要格式化标签的轴创建新的格式器。
示例
在中心经度为0的Plate Carree投影上标记从-180到180的倾斜度::
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)
在中心经度为180的Plate Carree投影上标记0到360的::
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)
当未绑定到轴时:
lon_formatter = LongitudeFormatter() ticks = [0, 60, 120, 180, 240, 300, 360] lon_formatter.set_locs(ticks) labels = [lon_formatter(value) for value in ticks]