I want add the repeated hatch patterns over a seaborn barplot.
Of course, I checked the below Q&A, but I cannot solve my question.
Is it possible to add hatches to each individual bar in seaborn.barplot?
In the above Q&A, the different patch patterns are applied to the left blue ('-') and the right blue ('+'). I want apply the same patch pattern to the same color bar; ("//") should be applied on the two blue bar, ("\\") should be applied on the two green bar, and ("|") should be applied on the two red bar.
I tried the below code, but I can not realize my ideal figure.
import matplotlib.pyplot as plt
import seaborn as sns
# Set style
sns.set(style="whitegrid", color_codes=True)
# Load some sample data
titanic = sns.load_dataset("titanic")
# Make the barplot
bar = sns.barplot(x="sex", y="survived", hue="class", data=titanic);
hatches = cycle([ "//" , "\\\\" , "|"])
# Loop over the bars
for i,thisbar in enumerate(bar.patches):
# Set a different hatch for each bar
thisbar.set_hatch(hatches[i])
plt.show()