How to change the linewidth of hatch in matplotlib?

后端 未结 4 1169
执笔经年
执笔经年 2021-02-05 08:47

Is there a way to increase the width of hatch in matplotlib?

For example, the following code by specifying linewidth only changes the width of the edge. I

4条回答
  •  梦毁少年i
    2021-02-05 08:51

    If you use pdf and have sudo rights you can change it in backend_pdf.py. There is a line

    self.output(0.1, Op.setlinewidth)
    

    Usually it is located in /usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py .

    Also someone wrote a hack to do this from your script (still need sudo rights to execute). Solution from here: http://micol.tistory.com/358

    import os
    import re
    import matplotlib
    
    def setHatchThickness(value):
    libpath = matplotlib.__path__[0]
    backend_pdf = libpath + "/backends/backend_pdf.py"
    with open(backend_pdf, "r") as r:
        code = r.read()
        code = re.sub(r'self\.output\((\d+\.\d+|\d+)\,\ Op\.setlinewidth\)',
                       "self.output(%s, Op.setlinewidth)" % str(value), code)
        with open('/tmp/hatch.tmp', "w") as w:
            w.write(code)
        print backend_pdf
        os.system('sudo mv /tmp/hatch.tmp %s' % backend_pdf)
    
    
    setHatchThickness(1.0)
    

提交回复
热议问题