I am trying to manipulate hatch of a countplot by hue. Here is the plot code and the corresponding plot I drew:
ax = sns.countplot(
data=data, y='M_pattern', hue='HHFAMINC',
palette=color_palette, lw=0.5, ec='black',
)
plt.yticks(rotation=45, ha='right')
legend_labels, _ = ax.get_legend_handles_labels()
hatches = ['-', '+', 'x', '\\']
# Loop over the bars
for i,thisbar in enumerate(bar.patches):
# Set a different hatch for each bar
thisbar.set_hatch(hatches[i])
plt.legend(
legend_labels, [
'Less than 10,000$ to 50,000$',
'50,000$ to 100,000$',
'100,000 to 150,000$',
'More than 150,000'
]
, title='Income categories'
)
plt.ylabel('Mandatory trip pattern')
plt.show()
Is there an straightforward way to hatch each income category separately?