searborn plot write legend on x-axis

23 Views Asked by At

I want to plot a barplot using seaborn where I have given x, y and hue. My problem is that hue is shown as legend. I want to show the hue on the a-axis itself. Is there any means to do so? Using the code below:

fig, ax = plt.subplots(figsize=(20, 10))
chart= sns.barplot(data=sorted_data, x="onlydate", y="cmn_pcr_oi_ratio",hue="strike_price",ax=ax)
label_per = [fmt_per.strftime('%Y-%m-%d') for fmt_per in data['onlydate']]
chart.set_xticklabels(label_per)
chart.set_xlabel('Date', fontdict={'size': 15})
chart.set_title('DateWise', fontdict={'size': 30, 'weight': 'bold', 'color': 'grey'})
def change_width(ax) :
    for patch in ax.patches :
        patch.set_width(0.05)

        
change_width(ax)
plt.savefig('datewise_chart_1.png')

I get the following: enter image description here

But I want to get output as below enter image description here

0

There are 0 best solutions below