2

I'm really suffering from this problem for so long.
Originally, after plotting something with matplotlib, I could easily save the image.
However, after installing scipy, I couldn't save my image anymore.
(I installed matplot and scipy by using pip.)
I tried to look up some information, but I still can't solve the problem.
My operating system is Mac OS X Lion (10.7)

I think the following links are some relevant issues

https://github.com/ipython/ipython/issues/2710
Matplotlib pylab savefig runtime error in python 3.2.3
matplotlib and libpng issues with ipython notebook
libpng15 static link issues

It seems that if I can relink the libraries or set DYLD_LIBRARY_PATH (actually I don't know what that is...)

Or maybe I have to recompile something?
By the way, I'm very new to linux-based system, so it would be really nice if someone could explain it in a relatively simple way. Thank you very much.

Below are some error messages:

libpng warning: Application was compiled with png.h from libpng-1.5.4
libpng warning: Application  is  running with png.c from libpng-1.4.10
libpng warning: Incompatible libpng version in application and library
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/Library/Python/2.7/site-packages/matplotlib/backends/backend_macosx.pyc in save_figure(self, *args)
    476         if filename is None: # Cancel
    477             return
--> 478         self.canvas.print_figure(filename)
    479 
    480     def prepare_configure_subplots(self):

/Library/Python/2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2094                 orientation=orientation,
   2095                 bbox_inches_restore=_bbox_inches_restore,
-> 2096                 **kwargs)
   2097         finally:
   2098             if bbox_inches and restore_bbox:

/Library/Python/2.7/site-packages/matplotlib/backend_bases.pyc in print_png(self, *args, **kwargs)
   1856         from backends.backend_agg import FigureCanvasAgg # lazy import
   1857         agg = self.switch_backends(FigureCanvasAgg)
-> 1858         return agg.print_png(*args, **kwargs)
   1859 
   1860     def print_ps(self, *args, **kwargs):

/Library/Python/2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    502             _png.write_png(renderer._renderer.buffer_rgba(),
    503                            renderer.width, renderer.height,
--> 504                            filename_or_obj, self.figure.dpi)
    505         finally:
    506             if close:

RuntimeError: Could not create write struct
Community
  • 1
  • 1
amigcamel
  • 1,879
  • 1
  • 22
  • 36
  • Do you want to solve this PNG problem or do you just want to use matplotlib on your Mac? – carlosdc Mar 29 '13 at 06:34
  • Yes, I have to solve the PNG problem since I have to save images for some reasons. – amigcamel Mar 29 '13 at 06:41
  • Save PNGs? A workaround would be to solve JPGs, for example. – carlosdc Mar 29 '13 at 06:43
  • Yes, I've thought about that, but it seems that I still have to save it as PNG first. (see: http://stackoverflow.com/questions/8827016/matplotlib-savefig-in-jpeg-format) – amigcamel Mar 29 '13 at 06:49
  • Not true. plt.savefig('output.jpg') works unless you specifically didn't install JPG support. – carlosdc Mar 29 '13 at 06:55
  • Ok, I think I've installed it with easy_install, but it seems that I got another problem. (see: http://stackoverflow.com/questions/5085229/python-package-installed-with-easy-install-is-not-being-detected-pil-1-1-7) – amigcamel Mar 29 '13 at 07:01

1 Answers1

7

If you save a JPG you don't need PNG support. There is no need for PIL either:

import pylab as pl
pl.plot([0.2,0.3,0.4], [0.1,0.2,0.3], label='series name')
pl.xlabel('x label')
pl.ylabel('y label')
pl.ylim([0.0, 1.0])
pl.xlim([0.0, 1.0])
pl.title('Title')
pl.legend(loc="lower left")
pl.savefig('output.jpg')
pl.show()
carlosdc
  • 12,022
  • 4
  • 45
  • 62