我正在运行Mac OSX 10.5.8。我使用macports安装了matplotlib。我从matplotlib画廊获得了一些像这样的示例,而没有做任何修改:
http://matplotlib.sourceforge.net/examples/api/unicode_minus.html
我运行它,没有错误,但是图片没有显示。在Linux Ubuntu中,我明白了。
您知道这里可能出什么问题吗?
我正在运行Mac OSX 10.5.8。我使用macports安装了matplotlib。我从matplotlib画廊获得了一些像这样的示例,而没有做任何修改:
http://matplotlib.sourceforge.net/examples/api/unicode_minus.html
我运行它,没有错误,但是图片没有显示。在Linux Ubuntu中,我明白了。
您知道这里可能出什么问题吗?
Answers:
我也可以在这方面进行验证。要解决,这是我所做的
sudo port install py25-matplotlib +cairo+gtk2
sudo port install py26-matplotlib +cairo+gtk2
另外,我们需要将默认后端更改为基于GUI的后端。
编辑文件~/.matplotlib/matplotlibrc
,然后添加:
backend: GTKCairo
另外,您可以尝试以下操作,这可能使您不需要GTK或Cairo后端。编辑~/.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()))
我遇到了同样的问题,甚至我都看到了如何创建一个新的应用程序窗口并立即消失。
简单的解决方案-仅检查您是否有
plt.show()
剧情之后
pylab
。谢谢!
import matplotlib.pyplot as plt
,然后让它显示出来。有点奇怪,但是效果很好!
plt.show()
则在代码块末尾需要。你可以通过调用检查状态plt.isinteractive()
和切换状态使用plt.ion()
和plt.ioff()
fig.show()
与...混淆plt.show()
。
当你尝试
plt.savefig('myfilename.png')
代替
plt.show()
会保存myfilename.png
当前路径中命名的正确图像吗?
在剧情之后,只需添加-
plt.show()
这项工作的原因与交互式和非交互式模式有关。如果后端以非交互方式打开,plt.show()
则在代码块末尾需要。您可以通过调用plt.isinteractive()
并使用plt.ion()
和切换状态来检查状态plt.ioff()
plt.show()
-我让我的情节显示出来,然后我在我的情节之前尝试plt.legend()
了plt.ion()
-我删除了plt.show()
,然后让我plt.isinteractive()
打印了True
,但仍然没有让我的情节显示出来。那么,应该怎么做plt.ion()
才能切换到交互模式-如果有人只是想检查这种方法是否有效而无需使用plt.show()
?
这对我有用:
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 git@github.com: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
backend: tkAgg
〜/ .matplotlib / matplotlibrc结合起来对我有用
我只有python 2.5,并且不想在Mac上安装python 2.6。因此,我使用以下链接中提到的不同过程来解决此问题:
http://www.gtkforums.com/viewtopic.php?f=3&t=54928
一个人实际需要的是以下步骤:
1)搜索目录“ pygtk-2.0.pc”在哪里并找到它。例如我的位于以下目录中:
/ opt /本地/ lib / pkgconfig
2)将路径信息添加到环境变量中。例如:
PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
export PKG_CONFIG_PATH
3)从matplotlib网站http://matplotlib.sourceforge.net/_static/matplotlibrc下载配置信息文件“ matplotlibrc”
4)在文件中将后端更改为MacOSX并保存
5)将文件复制到目录.matplotlib您可以通过以下命令在python中找到目录:
import matplotlib
matplotlib.get_configdir()
苹果有它自己的Python(从这里看,这是不是最好的),我会建议与蟒蛇沿着一些Python 3.7左右的只是一个干净的安装,然后将其介绍,作为译员PyCharm。一切都会正常运行,您将不需要添加“后端:MacOSX”之类的临时解决方案。
如果有人正在使用spyder,请执行以下操作。
1.)从Anaconda Launcher启动Spyder 2.3.5.2。2.)转到首选项-> IPython控制台->图形->后端:将其更改为“自动” 3.)选择“应用”并关闭首选项3.)重新启动IPython内核4.)创建简单的图形
sudo port install py37-matplotlib +cairo+gtk3
~/.matplotlib/matplotlibrc used
backend: MacOSX
在上面的unicode_minus.py示例中,似乎可以在MacOS Mojave 10.14.4和python 3.7上运行。
matplotliib
解决了我的问题。您可以在答案中找到许多好的建议/解决方案。如果它们都不起作用,请在放弃之前尝试重新安装matplotlib。