読者です 読者をやめる 読者になる 読者になる

回心誌

世の中わがんね

Cygwinのpythonでepsが出力できない。

Cygwinpythonでmatplotlibがうまく動かない。
epsを吐き出そうとすると、エラーが出る。
なんでか分からん。

Traceback (most recent call last):
  File "plotOneAgent.py", line 88, in <module>
    plt.savefig(patho,format="eps")
  File "/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 472, in savefig
    return fig.savefig(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/figure.py", line 1370, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2096, in print_figure
    **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1843, in print_eps
    return ps.print_eps(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 974, in print_eps
    return self._print_ps(outfile, 'eps', *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 1007, in _print_ps
    **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 1100, in _print_figure
    self.figure.draw(renderer)
  File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/figure.py", line 1006, in draw
    func(*args)
  File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/axes.py", line 2086, in draw
    a.draw(renderer)
  File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/axis.py", line 1055, in draw
    tick.draw(renderer)
  File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/axis.py", line 240, in draw
    self.label1.draw(renderer)
  File "/usr/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/text.py", line 596, in draw
    ismath=ismath)
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 748, in draw_text
    self.track_characters(font, s)
  File "/usr/lib/python2.7/site-packages/matplotlib/backends/backend_ps.py", line 236, in track_characters
    realpath, stat_key = get_realpath_and_stat(font.fname)
  File "/usr/lib/python2.7/site-packages/matplotlib/cbook.py", line 796, in __call__
    stat = os.stat(realpath)
OSError: [Errno 2] No such file or directory: '/cygdrive/c/Users/username/Dropbox/Source/Python/C:\\Python27\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf'

よく分からないが、ググってたら同じような症状があったので、それに従って直せた。

class GetRealpathAndStat:
   def __init__(self):
     self._cache = {}
   def __call__(self, path):
     result = self._cache.get(path)
     if result is None:
         realpath = os.path.realpath(path)
         if sys.platform == 'win32':
            stat_key = realpath
         else:
            realpath = path
            stat = os.stat(realpath)
            stat_key = (stat.st_ino, stat.st_dev)
         result = realpath, stat_key
         self._cache[path] = result
      return result
get_realpath_and_stat = GetRealpathAndStat()

/usr/lib/python2.7/site-packages/matplotlib/cbook.pyのl.795辺り。
else文の中に realpath = path を追加すればいいっぽい。