Matplotlib plots can be saved as image files using the plt. savefig() function. The plt. savefig() function needs to be called right above the plt.
pyplot. savefig() As the name suggests savefig() method is used to save the figure created after plotting data.
The issue actually stems from the matplotlib backend not being properly set, or from a missing dependency when compiling and installing matplotlib.
MatPlotLib with PythonJust using the savefig method of the pyplot package and mentioning the file format, we can save the output as a SVG format.
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?
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.
[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
# 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.
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.
gui_support
option that I need to configure in setup.cfg
and then recompile matplotlib?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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With