matplotlib.pyplot函数创建新图形而不是应用于当前图形 [英] matplotlib.pyplot functions creating new figures instead of applyting to the current one

查看:30
本文介绍了matplotlib.pyplot函数创建新图形而不是应用于当前图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习 matplotlib,遵循

您应该尝试升级到更新的版本(我使用的是 3.2.2).

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.

解决方案

  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).

这篇关于matplotlib.pyplot函数创建新图形而不是应用于当前图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆