2

私は本当に長い間この問題に苦しんでいます。
もともと、matplotlib で何かをプロットした後、簡単に画像を保存できました。
しかし、scipy をインストールした後、イメージを保存できなくなりました。
(pipを使用してmatplotとscipyをインストールしました。)
いくつかの情報を調べようとしましたが、まだ問題を解決できません。
私のオペレーティング システムは Mac OS X Lion (10.7) です。

次のリンクはいくつかの関連する問題だと思います

https://github.com/ipython/ipython/issues/2710
Python 3.2.3 での Matplotlib pylab savefig ランタイム エラー
ipython ノートブックでの matplotlib および libpng の問題
libpng15 静的リンクの問題

ライブラリを再リンクしたり、DYLD_LIBRARY_PATHを設定したりできるようです(実際にはそれが何であるかわかりません...)

それとも、何かを再コンパイルする必要がありますか?
ところで、私はLinuxベースのシステムに非常に慣れていないので、誰かが比較的簡単な方法で説明できれば本当にうれしいです. どうもありがとうございました。

以下にいくつかのエラー メッセージを示します。

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
4

1 に答える 1

7

JPG を保存する場合、PNG のサポートは必要ありません。PIL も必要ありません。

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()
于 2013-03-29T07:11:09.463 に答える