2010-03-24 52 views

回答

39

我可以在我的最后验证这一点。要修复,这是我做的

sudo port install py25-matplotlib +cairo+gtk2 
sudo port install py26-matplotlib +cairo+gtk2 

此外,我们需要将默认后端更改为基于GUI的后端。

编辑文件~/.matplotlib/matplotlibrc,并添加:

backend: GTKCairo 

此外,您还可以尝试以下方法,它可以让你不需要GTK或开罗后端。 编辑~/.matplotlib/matplotlibrc并添加:

backend: MacOSX 

与安装的那些变异的端口,这个工作为好,但它不需要X11。


顺便说一句,我看到的错误是以下几点:

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/__init__.py:41: UserWarning: 
Your currently selected backend, 'Agg' does not support show(). 
Please select a GUI backend in your matplotlibrc file ('/Users/wlynch/.matplotlib/matplotlibrc') or with matplotlib.use() 
(backend, matplotlib.matplotlib_fname())) 
+0

现在它的作品,非常感谢! – flow 2010-03-25 13:13:36

+1

你是一个拯救生命的人。花了3个多小时后,我安装了所有端口后,终于测试了我的脚本,并且它不会显示出来。太感谢了。 – rwilliams 2010-11-03 05:56:47

+2

你最终选择了哪一个? MacOSX后端还是GTKCairo? – 2010-11-03 13:12:12

8

当您尝试的

plt.savefig('myfilename.png') 

代替

plt.show() 

这是否保存在当前路径下命名myfilename.png正确的图像?

+0

另外:这表明(对“不显示你可能需要有一个matplotlibrc文件(首先搜索它)并将后端更改为tkAgg:http://newmediaandcapitalmarkets.org/component/content/article/68-how-i-got-matplotlib-工作-ON-我-M acbook.html。你使用哪种Python? – ChristopheD 2010-03-25 00:01:23

+0

良好的解决方法! – user1893354 2018-01-17 22:37:21

3

只是添加注释,

的matplotlibrc文件不存在我的系统上,我不得不从matplotlib网站下载一个副本。未来的用户可能也必须这样做。

+0

谢谢。这就是我错过的! – pocketfullofcheese 2011-10-05 05:29:52

2

我只有Python 2.5,我不想在我的Mac上安装Python 2.6。所以我用了以下链接中提到的不同方法来解决这个问题:

http://www.gtkforums.com/viewtopic.php?f=3&t=54928

什么是一个真正需要的是以下步骤:

1)在搜索哪里是目录“pygtk- 2.0.pc“并找到它。例如矿物位于以下目录:

/选择/本地/ LIB/pkgconfig

2)添加的路径信息,以envirement变量。例如:

PKG_CONFIG_PATH=/opt/local/lib/pkgconfig 
export PKG_CONFIG_PATH 

3)matplotlib网站 http://matplotlib.sourceforge.net/_static/matplotlibrc

4)更改后台下载的配置信息文件 “matplotlibrc” 到MacOSX的文件中,并将其保存

5)复制文件到目录.matplotlib 您可以通过以下命令在python中找到目录:

import matplotlib 
matplotlib.get_configdir() 
2

这是对我工作:

brew install pkg-config 
brew link pkg-config 
brew install pygtk 
brew install freetype 
brew install libpng 

sudo ln -s /usr/local/Cellar/freetype/*/lib/pkgconfig/freetype2.pc /usr/local/lib/pkgconfig/freetype2.pc 

git clone [email protected]:matplotlib/matplotlib.git 
cd matplotlib 
python setup.py build 
python setup.py install 

参考文献:

http://blog.caoyuan.me/2012/08/matplotlib-error-mac-os-x/ http://matplotlib.org/faq/installing_faq.html#install-from-git http://www.tapir.caltech.edu/~dtsang/python.html

+0

这与在〜/ .matplotlib/matplotlibrc中放入'后端:tkAgg'相结合 – user2079802 2016-06-02 03:39:29

+0

Thanks for ton!在谷歌的所有痛苦漫游后,终于这解决了我的问题! – hmi 2016-09-07 06:09:55

16

这是对我工作。我只是改变了进口Matplotlib

import matplotlib 
matplotlib.use('TkAgg') 
import matplotlib.pyplot as plt 
+0

这也适用于我在虚拟环境中的mac OS X上 – 2017-06-19 22:05:59

43

的我有同样的问题,甚至我可以看到如何创建一个新的应用程序窗口,并立即消失。

简单的解决方案 - 只是检查,如果你有

plt.show() 

情节

+1

这是最适合我的最简单的答案。我不必安装任何额外的软件包或配置任​​何东西。只是称为plot.show()和图像出现。 – 2016-06-28 08:46:00

+1

这对我''pylab'同样的问题。谢谢! – 2016-12-25 00:59:12

+0

也为我工作。这是必要的,因为一个错误或是故意你需要调用show()? – gph 2017-07-01 19:48:58

-1

只需复制在终端粘贴此之后:

echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc