xshaun's NoteBook

What makes the desert beautiful is that somewhere it hides a well.

Follow me on GitHub

问题

使用 matplotlib 生成的eps文件,不含hatch等,比如柱状的阴影等。

解决方案:

根据操作系统,找到 matplotlib 的安装目录下的backend_ps.py文件。以 Ubuntu 为例,文件路径为/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_ps.py

gsavegrestore 加入 self._pswriter.write 函数中:

# 加入前
""" % locals())
        self._pswriter.write(
            self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen),
                               simplify=False))
        self._pswriter.write("""\
        fill
        stroke
     } bind
   >>
   matrix
   0.0 %(pageheight)f translate
   makepattern
   /%(name)s exch def
""" % locals())

# 加入后
""" % locals())
        self._pswriter.write(
            self._convert_path(Path.hatch(hatch), Affine2D().scale(sidelen),
                               simplify=False))
        self._pswriter.write("""\
        gsave               #<<--------------------
        fill
        grestore            #<<--------------------
        stroke
     } bind
   >>
   matrix
   0.0 %(pageheight)f translate
   makepattern
   /%(name)s exch def
""" % locals())

GO-BACK     UP-LEVEL TOP