[Matplotlib-users] Advanced usage of custom hatch with fill_between

christian at fredborg-braedstrup.dk christian at fredborg-braedstrup.dk
Wed Sep 28 09:41:39 EDT 2016


Hi,

I would like to make some quite advanced custom hatches and can't figure
out the best way to do it in matplotlib. I am not even sure hatches are
the best way too go about it. Have considered using a png or similar and
overlay that on the image. But I would like to use the fill_between
command and that does not support using pngs in that way.

Here is a example of what I would like my hatch to look like,

http://fredborg-braedstrup.dk/hatch_examples.png

This stack overflow question got me a bit of the way:
http://stackoverflow.com/questions/17285154/how-to-fill-a-polygon-with-a-custom-hatch-in-matplotlib

I have therefore made a polygon to draw the "T" like symbol on a unit
rectangle,

T_path = Polygon(
    [[0.0, -0.2], [0.0, 0.0], [-0.4, 0.0], [0.4, 0.0], [0.0, 0.0], [0.0,
    -0.4]],
    closed=True, fill=False).get_path()

but the symbols are too small and closely spaced.  I have a example
here,

http://fredborg-braedstrup.dk/hatch_mpl_example.png

Is it possible to enlarge the individual symbols (T's) without having
them clip on the unit rectangle? Or perhaps it is possible to only plot
every 5th symbol? It seems quite easy when creating hatch lines and
adding space but I have not found a good solution for general polygons
yet.

If a solution exists without using hatches I am all open to that. Hope
someone can point me in the right direction on this.

Thanks,
Christian


More information about the Matplotlib-users mailing list