简体   繁体   English

Mac上的matplotlib不显示

[英]matplotlib on mac doesn't display

There are a lot of questions about installing matplotlib on mac, but as far as I can tell I've installed it correctly using pip and it's just not working. 关于在Mac上安装matplotlib的问题很多,但据我所知,我已经使用pip正确安装了它,但是它不起作用。 When I try and run a script with matplotlib.pyplot.plot(x, y) nothing happens. 当我尝试使用matplotlib.pyplot.plot(x,y)运行脚本时,没有任何反应。 No error, no nothing. 没错,没事。

import matplotlib.pyplot

x = [1,2,3,4]
y = [4,3,2,1]

matplotlib.pyplot.plot(x, y)

When I run this in the terminal in a file called pyplot.py I get this: 当我在终端中运行一个名为pyplot.py的文件时,我得到以下信息:

pgcudahy$ python pyplot.py
pgcudahy$ 

No errors, but no plot either. 没有错误,但也没有情节。 In an interactive python shell I get this: 在交互式python shell中,我得到了:

>>> import matplotlib
>>> print matplotlib.__version__
1.1.1
>>> print matplotlib.__file__
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.pyc

Which leads me to believe it's installed correctly. 这使我相信它已正确安装。

Any ideas? 有任何想法吗?

You need to call the show function. 您需要调用show函数。

import matplotlib.pyplot as plt

x = [1,2,3,4]
y = [4,3,2,1]

plt.plot(x, y)
plt.show()

It's likely that the plot is hidden behind the editor window or the spyder window on the screen. 绘图可能隐藏在屏幕上的编辑器窗口或spyder窗口后面。 Instead of changing matplotlib settings, just learn the trackpack gestures of the mac, "app exposé" is the one you need to make your plots visible (see system preferences, trackpack). 无需更改matplotlib设置,只需学习Mac的Trackpack手势即可,“ appexposé”是使绘图可见的一种方法(请参阅系统偏好设置,trackpack)。 Then click on the figure to raise it to the front. 然后单击该图将其提升到前面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM