- 在采用Python的matplotlib编程过程中出现以下的问题:
“MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
plt.subplot(2,1,1)”
-
经过一下午的查证,试验发现是由于缺少plt.figure()语句,在大多数绘图中,并没有使用plt.figure(),而是直接使用plt.subplot(),这个函数在单个文档运行时是没有问题的,但采用pyqt5编程调用绘图模块时就出错,因此,提醒大家添加plt.figure()。
-
源程序:
[code]plt.subplot(2,1,1)plt.plot(x_label, value) # 1表示文件中每一行2个数字作为横坐标,0表示文件中每一行第一个数字作为纵坐标plt.xlim(0, x_label[-1] + 0.1)y1_temp=min(value)y2_temp=max(value)
- 修改后
[code]plt.figure()plt.subplot(2,1,1)plt.plot(x_label, value) # 1表示文件中每一行2个数字作为横坐标,0表示文件中每一行第一个数字作为纵坐标plt.xlim(0, x_label[-1] + 0.1)y1_temp=min(value)y2_temp=max(value)
- 添加一句,问题解决。
- 希望能对大家有所帮助。