matplotlib contourf plot中缺少楔形

时间:2013-11-18 04:40:14

标签: python numpy matplotlib contour

我正在尝试在matplotlib中绘制一个等高线图,并且我不断得到一个缺失的“楔形”。以下示例说明了我正在尝试做的事情。

import numpy as np
import matplotlib.pyplot as plt

ph_cut = 0.05
nphi = 13
phi = np.linspace(ph_cut,2*np.pi-ph_cut, nphi)

nr  = 50
rmax=1
rr  = np.linspace(0, rmax, nr)
PH, RR = np.meshgrid(phi,rr)

X = RR * np.cos(PH)
Y = RR * np.sin(PH)
Z = np.sin(PH)

nlev = 13
levels=np.linspace(-1, 1, nlev)

cs=plt.contourf(X,Y,Z, levels)

plt.colorbar(cs)
plt.show()

-ph_cut和ph_cut之间的楔子永远不会被填充。 matplotlib是否无法进行插值?严格来说,这个区域没有什么不同,并且没有比pi + ph_cut的相应pi-ph_cut更少的信息......我试着四处寻找但找不到任何解决方案。

1 个答案:

答案 0 :(得分:0)

请不要遗漏:

import numpy as np
import matplotlib.pyplot as plt

ph_cut = 0.05
nphi = 13
phi = np.linspace(0,2*np.pi, nphi)

nr  = 50
rmax=1
rr  = np.linspace(0, rmax, nr)
PH, RR = np.meshgrid(phi,rr)

X = RR * np.cos(PH)
Y = RR * np.sin(PH)
Z = np.sin(PH)

nlev = 13
levels=np.linspace(-1, 1, nlev)

cs=plt.contourf(X,Y,Z, levels)

plt.colorbar(cs)
plt.show()

enter image description here