我正在一个人物上绘制3张地图。出于某种原因,当我去标记xaxis时,数字都被填充在图的一侧。有没有人把价值空间分开?
for j in xrange(0,3):
data = mydatalist[j]
a.append(fig.add_subplot(3,2,j+1))]
m.append(Basemap(projection='mill', llcrnrlat=-90, urcrnrlat=90, \
llcrnrlon=30,urcrnrlon=390, resolution='c', ax=a[j]))
x=np.linspace(30,390,288)
y = np.linspace(-90, 90, 234)
x, y = np.meshgrid(x, y)
x, y = m[j](x,y)
cintervals = [-0.1,-0.09, -0.08, -0.07, -0.06,-0.05, -0.04, -0.03, -0.02,-0.01,\
0, 0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1]
mesh = m[j].contourf(x,y,data,cintervals, cmap=plt.cm.jet)
xlab=np.concatenate([np.arange(30,181,30),np.arange(-150,31,30)])
plt.xticks(np.linspace(30, 390, 13),xlab)
plt.tick_params(labelsize=8)
plt.show()
答案 0 :(得分:0)
切换到Gall立体投影解决了我的问题,虽然我不确定为什么它不能用于米勒投影。
答案 1 :(得分:0)
您的问题是地图坐标与纬度/经度
之间的坐标不匹配您可以根据
指定沿x轴间隔显示的x刻度np.linspace(30, 390, 13)
但是 - 如果您在x
中查看您的值(即您在contourf
行中正在绘制的实际x坐标),您会看到它们来自0
到40030154.74248523
。
为避免这种情况 - 替换
plt.xticks(np.linspace(30, 390, 13),xlab)
与
plt.xticks(np.linspace(min(x[0]),max(x[0]), len(xlab)),xlab)
注意 - 您可以使用更小但完整的示例生成此效果,这可能有助于您隔离问题。看一下如何生成Minimal, complete and verifiable example。目前,您的代码无法运行,因为它缺少a
,m
,mydatalist
和所需的导入。
我已经提供了您可能提供的下面的代码 - 保留子图循环 - 尽管实际上即使只有一个图而不是子图,您也可能获得相同的效果。
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np
x=np.linspace(30,390,288)
y = np.linspace(-90, 90, 234)
xg, yg = np.meshgrid(x, y)
fig = plt.figure()
for j in xrange(0,3):
a = fig.add_subplot(3,2,j+1)
m = Basemap(projection='mill', llcrnrlat=-90, urcrnrlat=90, llcrnrlon=30,urcrnrlon=390, resolution='c', ax=a)
m.drawcoastlines() # Just put something on the map - doesn't need to be your complex contour plot
x, y = m(xg,yg)
#You can see the problem with using hard-coded 30,390 if you print this
#x=30 and x=390 are both in the lowest 0.001% of the x axis
#print x
xlab=np.concatenate([np.arange(30,181,30),np.arange(-150,31,30)])
plt.xticks(np.linspace(30,390,13),xlab)
#Working version commented below
#plt.xticks(np.linspace(min(x[0]),max(x[0]), len(xlab)),xlab)
plt.tick_params(labelsize=8)
plt.show()