gpt4 book ai didi

python - matplotlib 等高线图 : warning about `no contour levels were found`

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:24 26 4
gpt4 key购买 nike

我正在研究博客上的一个示例 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参数仍然是正确的名称。所以不确定是什么导致了这个错误。

最佳答案

0 的正弦值为 0。因此,您得到一个完整的 G 切片,即第一个 G[:,:,0],它全为零在里面。零不是级别之一,但即使是,也没有定义绘制常量数组的轮廓(完整的表面应该是轮廓线吗?)

因此 matplotlib 会正确警告您此帧中没有要绘制的轮廓。

关于python - matplotlib 等高线图 : warning about `no contour levels were found` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48408123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com