Matplotlib 绘图未显示在 Mac OSX 中?
我运行的是 Mac OSX 10.5.8。我使用 macports 安装了 matplotlib。我从 matplotlib 库中得到了一些示例,如下所示,无需修改:
http://matplotlib。 sourceforge.net/examples/api/unicode_minus.html
我运行它,没有错误,但图片不显示。在 Linux Ubuntu 中我明白了。
你知道这里可能出了什么问题吗?
I am running Mac OSX 10.5.8. I installed matplotlib using macports. I get some examples from the matplotlib gallery like this one, without modification:
http://matplotlib.sourceforge.net/examples/api/unicode_minus.html
I run it, get no error, but the picture does not show up. In Linux Ubuntu I get it.
Do you know what could be wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我遇到了同样的问题,即使我可以看到新的应用程序窗口是如何创建并立即消失的。
是否有
简单的解决方案 - 只需检查情节后
I had the same problem, even I could see how a new application window was created and immediately disappeared.
Simple solution - just check if you have
after the plot
我也可以在我这边验证这一点。为了解决这个问题,我做了以下操作。
另外,我们需要将默认后端更改为基于 GUI 的后端。
编辑文件
~/.matplotlib/matplotlibrc
,并添加:另外,您可以尝试以下操作,这可能允许您不需要 GTK 或 Cairo 后端。
编辑
~/.matplotlib/matplotlibrc
并添加:安装了这些变体的端口后,这也可以工作,但不需要 X11。
顺便说一句,我看到的错误如下:
I can verify this on my end as well. To fix, here's what I did
Also, we need to change the default backend to a GUI based one.
Edit the file
~/.matplotlib/matplotlibrc
, and add:Also, you can try the following, which may allow you to not need the GTK or Cairo backends.
Edit
~/.matplotlib/matplotlibrc
and add:With the port with those variants installed, this works as well, but it doesn't require X11.
By the way, the error that I saw was the following:
这对我有用。我刚刚更改了 Matplotlib 的导入
This is what worked for me. I just changed the import of Matplotlib
当您尝试
而不是
在当前路径中保存名为
myfilename.png
的正确图像时?When you try
instead of
does that save the correct image named
myfilename.png
in the current path?在绘图后只需添加 -
plt.show()
其工作原理是与交互模式和非交互模式有关。如果后端以非交互模式打开,则代码块末尾需要
plt.show()
。您可以通过调用plt.isinteractive()
检查状态,并使用plt.ion()
和plt.ioff()
切换状态After the plot simply add -
plt.show()
The reason this works is to do with interactive vs non-interactive mode. If the backend is opened in non-interactive mode,
plt.show()
is required at the end of the code chunk. You can check the status by callingplt.isinteractive()
and toggle the status usingplt.ion()
andplt.ioff()
我想为我分享这个可行的解决方案,
I wanna share this workable solution for me,
只是添加注释,
我的系统上不存在 matplotlibrc 文件,我必须从 matplotlib 网站下载一个副本。未来的用户可能也必须这样做。
just to add a note,
The matplotlibrc file was not present on my system and I had to to download a copy from the matplotlib website. Future users may have to do the same.
这对我有用:
参考文献:
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
This is what worked for me:
References:
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
我只有 python 2.5,我不想在我的 mac 上安装 python 2.6。因此,我使用以下链接中提到的不同过程来解决此问题:
http: //www.gtkforums.com/viewtopic.php?f=3&t=54928
实际需要的是以下步骤:
1)搜索目录“pygtk-”在哪里2.0.pc”并找到它。例如我的位于以下目录:
/opt/local/lib/pkgconfig
2) 将路径信息添加到环境变量中。例如:
3)从matplotlib网站下载配置信息文件“matplotlibrc”
http://matplotlib.sourceforge.net/_static/matplotlibrc
4) 将后端更改为 MacOSX文件并保存
5) 将文件复制到目录 .matplotlib
您可以通过以下命令找到python中的目录:
I only had python 2.5 and I did not want to install python 2.6 on my mac. So I used different procedure mentioned in the following link to solve this problem:
http://www.gtkforums.com/viewtopic.php?f=3&t=54928
What that one actually needs is the following steps:
1) Searching where is the directory "pygtk-2.0.pc" and locate it. For example mine was located in the following directory:
/opt/local/lib/pkgconfig
2) Adding the path information to envirement variable. For example:
3) Download the configuration information file "matplotlibrc" from matplotlib website
http://matplotlib.sourceforge.net/_static/matplotlibrc
4) Change backend to MacOSX in the file and save it
5) Copy the file to directory .matplotlib
You can locate the directory in python by the following command:
Mac 自带了自己的 Python。更多详细信息可以在 Matplotlib 常见问题解答中找到,但它是不是最好的解释。
我建议只干净安装一些 Python 3.7 左右以及 Anaconda,然后将它们作为 PyCharm 的解释器引入。一切都会正常工作,您不需要添加临时解决方案,例如
backend: MacOSX
等。Mac comes with its own Python. More details can be found in the Matplotlib FAQ, but it's not the best explanation.
I would suggest just a clean install of some Python 3.7 or so along with Anaconda and then introduce them as interpreters to PyCharm. Anything will work fine and you wont need to add ad-hoc solutions like
backend: MacOSX
or so.似乎可以在 unicode_minus.py 示例上使用 python 3.7 在 MacOS Mojave 10.14.4 上工作a> 如上所述。
Seemed to work on MacOS Mojave 10.14.4 with python 3.7 on the unicode_minus.py example above.
如果有人使用spyder,请执行以下操作。
1.) 从 Anaconda Launcher 启动 Spyder 2.3.5.2
2.) 转到首选项 -> IPython 控制台 ->图形->后端:将其更改为“自动”
3.) 选择“应用”并关闭首选项
3.) 重启IPython内核
4.) 创建简单的图形,例如
Do the following if anyone is using spyder.
1.) Start Spyder 2.3.5.2 from Anaconda Launcher
2.) Go to preferences -> IPython console -> Graphics -> Backend: changed it to "Automatic"
3.) Select "Apply" and close preferences
3.) Restart IPython kernel
4.) Create simple graphic like
作为一种临时解决方案,可以将图形保存为 .png/.jpg/.pdf 并暂时使用该文件。
As a temporary work around one can save the figure to a .png/.jpg/.pdf and make use of that file for the moment.
康达
(Ana)conda 中提供的默认 python 不是框架构建。但是,无论是在主环境还是在 conda envs 中,都可以轻松安装框架构建:安装 python.app (conda install python.app) 并使用 pythonw 而不是 python。
conda
The default python provided in (Ana)conda is not a framework build. However, a framework build can easily be installed, both in the main environment and in conda envs: install python.app (conda install python.app) and use pythonw rather than python.