How can I add textures to my bars and wedges?

前端 未结 3 1976
野的像风
野的像风 2020-12-01 04:41

I\'m drawing several bar and pie charts using matplotlib.pyplot.bar() and matplotlib.pyplot.pie(). In both functions, I can change the colors of the bars and wedges.

<
3条回答
  •  孤街浪徒
    2020-12-01 05:31

    With bar(), you can directly use hatches (with some backends): http://matplotlib.org/examples/pylab_examples/hatch_demo.html: bar plot with hatches

    It works by adding the hatch argument to your call to bar().


    As for pie(), it does not have a hatch keyword. You can instead get the individual pie chart patches and add hatches to them: you get the patches with:

    patches = pie(…)[0]  # The first element of the returned tuple are the pie slices
    

    then you apply the hatches to each slice (patch):

    patches[0].set_hatch('/')  # Pie slice #0 hatched.
    

    (hatches list at https://matplotlib.org/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_hatch).

    And you apply the changes with:

    pyplot.draw()
    

    Hatched pie chart]

提交回复
热议问题