【发布时间】:2020-01-23 21:04:47
【问题描述】:
我正在尝试从 cartopy geoaxes 中检索 yaxis 和 xaxis 刻度位置。
据我了解,一个常见的matplotlib的Axes有内部方法:'axes.get_xticks'和'axes.get_yticks'。
尽管如此,来自 geoaxes 的 cartopy 网格线却没有。我怎样才能找回它们?
此外,当我尝试使用通用格式(即:“axes.get_yticks”)从地理坐标轴中检索刻度时,我会得到奇怪的坐标。
这是一个例子。
import pandas as pd
pd.set_option('display.width', 50000)
pd.set_option('display.max_rows', 50000)
pd.set_option('display.max_columns', 5000)
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib.offsetbox import AnchoredText
def main(projection = ccrs.Mercator(), drawlicense=True):
fig = plt.figure(figsize=(9,7))
ax = plt.axes(projection=projection)
# Put a background image on for nice sea rendering.
ax.stock_img()
# Create a feature for States/Admin 1 regions at 1:50m from Natural Earth
states_provinces = cfeature.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none')
SOURCE = 'Natural Earth'
LICENSE = 'public domain'
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(states_provinces, edgecolor='gray')
# Add a text annotation for the license information to the
# the bottom right corner.
if drawlicense:
text = AnchoredText(r'$\mathcircled{{c}}$ {}; license: {}'
''.format(SOURCE, LICENSE),
loc='right',
bbox_transform=ax.transAxes,
bbox_to_anchor=(1.01, -0.02),
prop={'size': 8},
frameon=False)
ax.add_artist(text)
plt.show()
return ax
ax = main()
Gridliner = ax.gridlines(draw_labels=True)
在上述情况下,如果我尝试从地轴“ax”中检索 yticks,我最终会得到一组奇怪的值:
在:ax.get_yticks()
输出: 数组([-20000000., -15000000., -10000000., -5000000., 0., 5000000., 10000000., 15000000., 20000000.])
请注意,这些值不是以度数为单位的,尽管该图和选定的 cartopy 的投影都表示度数坐标。
因此,我做错了什么?如何获取地图各自的度坐标?
此致,
【问题讨论】:
-
这些是轴坐标中的刻度位置,尝试
ax.get_xticklabels()获取标签(图中显示的内容) -
亲爱的威廉米勒,感谢您的回复。 “ax.get_xticklabels()”方法确实有效。然而,上述数字不能在轴坐标中。轴坐标在零和一之间变化,以上数值都在千以上。
标签: python-3.x matplotlib cartopy