How can I apply different hatches to my data, just as I can define different colours as a tuple?
#!/usr/bin/env python3
import pandas
from matplotlib import pyplot as plt
data = {"Label 1": [2,3,5,10], "Label 2": [1,2,4,8]}
pandas.DataFrame(data).plot.bar(color=("grey", "white"), hatch=("/", "*"))
plt.show()
With this code, Hatches apply to all bars altogether.
Hatches are applied altogether to all bars. Instead, I'd rather have each data set using its own hatch-colour combination.
I know that I can manually modify each patch in the plot like this:
ax = pandas.DataFrame(data).plot.bar(color=("grey", "white"), legend=False)
for container, hatch in zip(ax.containers, ("/", "*")):
for patch in container.patches:
patch.set_hatch(hatch)
ax.legend(loc='upper center')
plt.show()
Manually set hatch to patches:
This is kind of hacky, but the best solution, I have found via this discussion.
What is the proper way of applying hatches to different data sets in a combined plot?