Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib`figure.show()`在Mac OSX上不显示任何内容_Python_Macos_Matplotlib - Fatal编程技术网

Python Matplotlib`figure.show()`在Mac OSX上不显示任何内容

Python Matplotlib`figure.show()`在Mac OSX上不显示任何内容,python,macos,matplotlib,Python,Macos,Matplotlib,我使用的是最新的matplotlib,版本2.0.0,通过Mac OSX Sierra上的pip安装。问题是下面的示例没有按预期工作,因为没有显示任何图形。请注意,我正在调用figure1对象上的show(),因为我只想显示figure1。如果我使用plt.show()它可以工作,但是它同时显示了图1和图2,这是我不想要的 import matplotlib.pyplot as plt figure1 = plt.figure() # I need figure2 for something

我使用的是最新的matplotlib,版本2.0.0,通过Mac OSX Sierra上的pip安装。问题是下面的示例没有按预期工作,因为没有显示任何图形。请注意,我正在调用
figure1
对象上的
show()
,因为我只想显示
figure1
。如果我使用
plt.show()
它可以工作,但是它同时显示了
图1
图2
,这是我不想要的

import matplotlib.pyplot as plt

figure1 = plt.figure()

# I need figure2 for something else but I don't want to show it.
figure2 = plt.figure()

figure1.show()

# The following would work, but I want to show
# only figure1 and not also figure2.
# plt.show()
figure.show()
在交互模式下是有意义的,而不是永久性地显示图形。因此您需要使用
plt.show()
。为了不显示第二个图形,您可以先将其关闭

plt.close(figure2)
plt.show()

也许这就是你要找的,我还需要
图2
做点别的。有没有办法只显示
图1
而不丢失
图2
。我的意思是我需要
图2
,因为如果我想在不显示的情况下将其保存到磁盘上,如果我关闭它,我还能使用它吗?嗯。。。你确定吗?似乎我仍然能够保存它,即使在调用
plt.close('all')
你说得对,甚至更好。所以只要关闭你不想显示的图形,就可以了。