matplotlib.pyplot functions creating new figures instead of applyting to the current one

て烟熏妆下的殇ゞ 提交于 2021-02-11 03:40:16

问题


I'm starting to learn matplotlib, following the pyplot tutorial, but something weird—I think—is happening in the very first part.

When I do this,

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

plt.plot([1, 2, 3, 4]) creates the figure, but plt.ylabel('some numbers') creates another figure with the label but with no plot. Nothing about this is mentioned in the tutorial, and I have been reading about the plt functions to see if this is supposed to happen and/or how to fix it, but can't find anything. What can I do about this?

I just installed matplotlib 3.1.3 and I'm running Python 3.7.6 on Spyder 4.0.1

I see that, in this version of Spyder, I don't need to use plt.show(), because all figures are shown in the 'Plots' pane.

Thanks in advance.

EDIT 1

I HAVEN'T FOUND AN ANSWER FOR THIS.

If I copy and paste these two lines into my shell:

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')

I get the label applied to the figure with the plot, as it should, but, if I execute them one at a time, I get the situation described above. I'd like to know why this is happening and if it should be happening.


回答1:


  Okay I'm executing the same block of code and this is the returning output.

 You should try upgrade to a newer version (I've used 3.2.2).



来源:https://stackoverflow.com/questions/62794236/matplotlib-pyplot-functions-creating-new-figures-instead-of-applyting-to-the-cur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!