带有轴投影的matplotlib tricontourf

时间:2015-08-12 20:59:25

标签: python matplotlib

我正在尝试在球体上对不规则采样数据进行轮廓,但是tricontourf表现不佳。

问题的例子:

import numpy as np
import matplotlib.pyplot as plt
# Generate some random data points
ra = np.random.rand(100)*np.pi*2-np.pi
dec = np.random.rand(100)*np.pi-np.pi/2.
z = np.sin(ra)+np.cos(dec)

levels=100
# Contour the data
fig = plt.figure()
ax = fig.add_subplot(111)
TF = ax.tricontourf(ra,dec,z, levels)
fig.savefig('noproject.png')
# Contour with an aitoff projection
fig = plt.figure()
ax = fig.add_subplot(111, projection='aitoff')
TF = ax.tricontourf(ra,dec,z, levels)
fig.savefig('aitoff.png')

noproject.png aitoff.png

我可以使用mpl_toolkits.basemap来做,但我想避免依赖,因为它看起来应该可行。

1 个答案:

答案 0 :(得分:0)

以下是与底图

配合使用的证明
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
ra = np.random.rand(100)*np.pi*2-np.pi
dec = np.random.rand(100)*np.pi-np.pi/2.
z = np.sin(ra)+np.cos(dec)
levels=100

fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(projection='nplaea', boundinglat=20., lon_0=0., resolution='l')
MC = m.contourf(np.degrees(ra),np.degrees(dec),
                z, levels, ax=ax, tri=True, latlon=True)
m.drawparallels(np.arange(0,81,20))
m.drawmeridians(np.arange(-180,181,60))
fig.savefig('baseContour.png')

enter image description here