为什么保存按钮在 matplotlib 绘图上不起作用?

发布于 2024-09-18 08:58:23 字数 3685 浏览 6 评论 0原文

我在 Mac OS X 10.6 上的 Python 2.7 virtualenv 中安装了 matplotlib 1.0.0 。我可以很好地创建情节。但是,每当我按下保存按钮时,我都无法在保存对话框窗口中输入文本,也无法保存绘图。我唯一能做的就是点击取消。对于造成这种情况的原因以及如何解决它有什么想法吗?

alt text

Matplotlib 安装过程

我通过克隆安装了 matplotlib astraw 的 matplotlib github 存储库,然后大致遵循 HyperJeff 的安装说明对于 numpy/scipy/matplotlib。以下是 setup.cfgmake.osx 的潜在相关部分,包括我在编译和安装之前修改的部分。

setup.cfg

[egg_info]
tag_svn_revision = 1

[directories]
basedirlist = /Users/matthew/.virtualenvs/matplotlib-test

[status]
#suppress = True
#verbose = True

[provide_packages]

[gui_support]
#gtk = False
#gtkagg = False
#tkagg = False
wxagg = False
#macosx = False

[rc_options]
backend = MacOSX
#numerix = numpy

make.osx

# build mpl into a local install dir with
PREFIX=/Users/matthew/.virtualenvs/matplotlib-test
MPLVERSION=1.0rc1
PYVERSION=2.7
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.39
FREETYPEVERSION=2.3.11
MACOSX_DEPLOYMENT_TARGET=10.6
OSX_SDK_VER=10.6
ARCH_FLAGS="-arch i386-arch x86_64"

## You shouldn't need to configure past this point (but I did...)

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="${ARCH_FLAGS} -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="${ARCH_FLAGS} -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
FFLAGS="-arch i386 -arch x86_64"

修改 setup.cfgmake.osx 后,我发出以下命令来安装 matplotlib:

make -f make.osx fetch deps mpl_build mpl_install
python setup.py install

注意: sudo 不是必需的,因为我要安装到 virtualenv 中,而不是像 HyperJeff 那样安装到站点包中。

Python 安装

我使用 python.org 的适用于 Mac OS X 10.5 的 Python 2.7 PPC/i386/x86-64 Mac OS X 安装程序磁盘映像安装了 Python 2.7。感谢 Ned Deily对此问题的回答,我知道这个版本的Python 2.7无法在Mac OS X 10.6上运行IDLE或Tkinter。

问题

  1. 我安装的 Python 2.7 版本是否是导致问题的原因?我是否应该使用适用于 Mac OS X 10.3 至 10.6 的 Python 2.7 32 位 Mac OS X 安装程序磁盘映像重新安装 Python 2.7?
  2. 是否需要在 setup.cfg 中配置不同的 gui_support 选项,然后重新编译 matplotlib?

更新,2010 年 9 月 13 日下午 3:33

看来其他 Mac OS X 和 matplotlib 用户也遇到了同样的问题。在 matplotlib-users 邮件列表中, 两名用户报告在 Mac OS X 10.5 上遇到了同样的问题。不过,他们运行的是 matplotlib 0.99.1.1 和 0.99.1.2,而我安装的是 matplotlib 1.0.0。

更新时间:2010 年 9 月 14 日上午 8:18

matplotlib bug 2973874 于 2010 年 3 月 20 日打开,存在同样的问题。然而,它的优先级为 5,并且自从 bug 最初被打开以来就没有被修改过。以下是该错误的描述:

我正在运行6.0.1 enthought python distibution 64位Mac。如果运行绘图并单击保存,我会打开一个保存对话框窗口,我无法在文件名字段中输入文本。我可以选择现有文件,但仍然无法修改名称。如果我选择非 png 文件,它不会覆盖它。我得到一个同名但扩展名为 png 的文件。

I have matplotlib 1.0.0 installed in a Python 2.7 virtualenv on Mac OS X 10.6. I can create plots fine. However, whenever I press the Save button, I can't type text into the save dialog window nor can I save the plot. The only thing I can do is hit cancel. Any thoughts on what's causing this and how to fix it?

alt text

Matplotlib installation procedure

I installed matplotlib by cloning astraw's matplotlib github repository and then loosely following HyperJeff's Installation Instructions for numpy/scipy/matplotlib. Below are the potentially relevant sections of setup.cfg and make.osx, including the sections that I modified prior to compiling and installing.

setup.cfg

[egg_info]
tag_svn_revision = 1

[directories]
basedirlist = /Users/matthew/.virtualenvs/matplotlib-test

[status]
#suppress = True
#verbose = True

[provide_packages]

[gui_support]
#gtk = False
#gtkagg = False
#tkagg = False
wxagg = False
#macosx = False

[rc_options]
backend = MacOSX
#numerix = numpy

make.osx

# build mpl into a local install dir with
PREFIX=/Users/matthew/.virtualenvs/matplotlib-test
MPLVERSION=1.0rc1
PYVERSION=2.7
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.39
FREETYPEVERSION=2.3.11
MACOSX_DEPLOYMENT_TARGET=10.6
OSX_SDK_VER=10.6
ARCH_FLAGS="-arch i386-arch x86_64"

## You shouldn't need to configure past this point (but I did...)

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="${ARCH_FLAGS} -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="${ARCH_FLAGS} -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"

PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
FFLAGS="-arch i386 -arch x86_64"

After modifying setup.cfg and make.osx, I issued the following commands to install matplotlib:

make -f make.osx fetch deps mpl_build mpl_install
python setup.py install

Note: sudo isn't required, since I'm installing into a virtualenv instead of into the site-packages like HyperJeff is doing.

Python Installation

I installed Python 2.7 using python.org's Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5. Thanks to Ned Deily's answer to this SO question, I know that this version of Python 2.7 cannot run IDLE or Tkinter on Mac OS X 10.6.

Questions

  1. Could the version of Python 2.7 that I have installed be the cause of the problem? Should I reinstall Python 2.7 using the Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6?
  2. Is there a different gui_support option that I need to configure in setup.cfg and then recompile matplotlib?

Update, September 13, 2010, 3:33 PM

It appears that other Mac OS X and matplotlib users are having the same problem. In the matplotlib-users mailing list, two users reported having the same problem on Mac OS X 10.5. Although, they were running matplotlib 0.99.1.1 and 0.99.1.2 versus matplotlib 1.0.0 that I have installed.

Updated, September 14, 2010, 8:18 AM

matplotlib bug 2973874 was opened on 20-Mar-10 with the same issue. However, it's a priority 5 and hasn't been modified since the bug was originally opened. Below is the description from the bug:

I am running the 6.0.1 enthought python distibution 64bit Mac. If a run a plot and click save I get a save dialog window that opens, I canot enter text in the file name field. I can select an existing file but still cannot modify the name. If I select a non png file it does not overwrite it. I get a file with the same name but with the png extension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

秋日私语 2024-09-25 08:58:24

您需要让 OSX 相信 virtualenv 实际上是从应用程序包运行的。此处讨论的修复:

http://groups.google.com/group /python-virtualenv/browse_thread/thread/83fa4a12d22a30c8/744e19c194f1618a

并在这里实现:

https:/ /github.com/gldnspud/virtualenv-pythonw-osx

You need to convince OSX that the virtualenv is actually running from an Application Bundle. Fix discussed here:

http://groups.google.com/group/python-virtualenv/browse_thread/thread/83fa4a12d22a30c8/744e19c194f1618a

And implemented here:

https://github.com/gldnspud/virtualenv-pythonw-osx

此刻的回忆 2024-09-25 08:58:24

我的回答不能解决问题,但可以轻松解决它!您可以在终端中触摸具有正确文件扩展名的新文件。您可以在 matplotlib 窗口中用鼠标选择该文件并覆盖它。

My answer doesn't fix the problem but can workaround it easily! You can touch a new file with the correct file extension in a terminal. After you can choose this file with the mouse inside the matplotlib window and overwrite it.

把梦留给海 2024-09-25 08:58:24

要解决此问题:

使用 conda install python.app 安装 pythonw

然后在终端中使用 pythonw 而不是 python

例如

pythonw my_plot.py

希望这有帮助

To solve this:

Use conda install python.app to install pythonw.

Then use pythonw instead of python in your terminal.

E.g.

pythonw my_plot.py

Hope this helps

停滞 2024-09-25 08:58:24

对于那些 Thouis 方法不起作用的人:

我注意到一个简单的解决方法是更改​​ matplotlib 后端。以下是可用后端的列表:

http://matplotlib.org/faq /usage_faq.html#what-is-a-backend

请注意,您应该选择渲染器之一(即支持 show() 命令的渲染器)。您可能需要安装后端,但您可能安装了多个后端。

为此:

import matplotlib
matplotlib.use('Qt4Agg')    #replace 'Qt4Agg' with desired backend

警告:这应该在导入 pylab 等之前完成。

For those that Thouis method didn't work:

I noticed that a simple work around is to change matplotlib backend. Here is a list of available backends:

http://matplotlib.org/faq/usage_faq.html#what-is-a-backend

Note that you should choose one of the renderer ones (i.e. the ones that support show() command). You might need to install the backend, but you might have multiple ones installed.

To do so:

import matplotlib
matplotlib.use('Qt4Agg')    #replace 'Qt4Agg' with desired backend

Warning: This should be done BEFORE importing pylab, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文