matplotlib numpy-TypeError:无法读取未定义的属性'props'-图形未显示?

此代码在一台机器上有效,但在另一台机器上无效。我似乎无法通过依赖项来隔离问题。

来自https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/simple_plot.html

的示例代码

-

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0,2.0,0.01)
s = 1 + np.sin(2 * np.pi * t)

fig,ax = plt.subplots()
ax.plot(t,s)

ax.set(xlabel='time (s)',ylabel='voltage (mV)',title='About as simple as it gets,folks')
ax.grid()

fig.savefig("test.png")
plt.show()

-> TypeError:无法读取未定义的属性“ props”

此代码不会产生明确失败的堆栈跟踪。 TypeError:通过调用plt.show()返回。我尝试搜索此错误,但找不到任何报告。 (我添加了我正在处理的服务器上的visual-studio的屏幕截图。我可能会创建其他环境的docker,因为我首先应该这样做,以避免配置中断。)正确保存到文件。这只是plt.show()的问题。

np。版本 '1.17.2'

matplotlib。版本 '3.1.1'

screen-shot

graph-saves-correctly

fjxxq147 回答:matplotlib numpy-TypeError:无法读取未定义的属性'props'-图形未显示?

您能告诉我们它具体在哪一行失败吗?哪个函数调用会导致此问题?您可以注释所有内容,然后取消注释每一行,直到执行时发生错误。也许有这个问题的github页面。

我怀疑是ax.set()调用。以前从未见过,也从未使用过。可能在mpl 3.1.1中已弃用。显然,当您传递函数不知道的参数(xlabel,ylabel,title)时,可能会发生此错误:Uncaught TypeError: Cannot read property 'value' of undefined

作为测试,请尝试运行此命令:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0,2.0,0.01)
s = 1 + np.sin(2 * np.pi * t)

fig,ax = plt.subplots()
ax.plot(t,s)


ax.set_ylabel('voltage (mV)')
ax.set_xlabel('time (s)')
ax.set_title('About as simple as it gets,folks')
ax.grid()

fig.savefig("test.png")
plt.show()
本文链接:https://www.f2er.com/3169676.html

大家都在问