对于无等值线图,matplotlib.pyplot.contour会正确地抛出错误
UserWarning: No contour levels were found within the data range.
但是,我如何才能让我的脚本绕过这个错误,继续运行下一行代码(可能只是抛出一个空白图),而不会完全中止脚本呢?
发布于 2021-01-07 16:33:58
正如上面的注释所述,这只是一个警告,您的代码不应停止。如果在这种情况下可以显示一个空图,并且您只想执行suppress the warning,则可以执行以下操作:
import matplotlib.pyplot as plt
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="No contour levels were found within the data range.")
plt.contour([[1,1],[1,1]])https://stackoverflow.com/questions/65602473
复制相似问题