【发布时间】:2018-07-02 15:37:15
【问题描述】:
我在博客post 上研究了一个关于使用matplotlib. 绘制动画的示例,其中一个示例涉及等高线图——代码如下。但是,当我运行此代码时,我得到一个 UserWarning
UserWarning: No contour levels were found within the data range.
warnings.warn("No contour levels were found")
该图的代码如下。
x = np.linspace(-3,3,91)
t = np.linspace(0,25,30)
y = np.linspace(-3,3,91)
X3, Y3, T3 = np.meshgrid(x,y, t)
sinT3 = np.sin(2*np.pi*T3/T3.max(axis=2)[...,np.newaxis])
G = (X3**2 + Y3**2)*sinT3
contour_opts = {'levels': np.linspace(-9, 9, 10),
'cmap':'RdBu', 'linewidths': 2}
cax = ax.contour(x, y, G[..., 0], **contour_opts)
def animate(i):
ax.collections = []
ax.contour(x, y, G[..., i], **contour_opts)
anim = FuncAnimation(fig, animate, interval=100, frames = len(t)-1)
HTML(anim.to_html5_video())
情节仍然有效,但我不断收到用户警告。
我检查了matplotlib文档,发现levels参数仍然是正确的名称。所以不确定是什么导致了这个错误。
【问题讨论】:
标签: python matplotlib plot contour