0

Been trying to get the bar plot & line chart merged (one over the other) but not sure why it's going to the right, when their X axes are actually one over the other.

fig,ax1 = plt.subplots(figsize=(22,8))
sns.set_style("white")
plt.rcParams['font.family'] = 'Tableau_Book_Regular'

data=manager.iloc[:,:-1].melt('Source_Day', var_name='a', value_name='b')
ax1=sns.barplot(x='Source_Day', y='b', hue='a', data=data)
ax1.set_xticklabels(ax1.get_xticklabels(), rotation=0)

ax2 = ax1.twinx()
g1=manager[['Source_Day','%Activated']]
g1.columns=['Source_Day','Active']
g1['Active']=g1['Active'].astype(float).astype(int)
ax2.plot(g1['Source_Day'], g1['Active'],color="#e9c48f", lw=3)       
ax2.axes.get_yaxis().set_visible(False)
ax2.set_ylim([0,100])
ax2.figure.set_figwidth(22)
ax2.figure.set_figheight(8)

ax2.axes.get_xaxis().set_visible(True)

for tick in ax2.get_xticklabels():
    tick.set_color('black')  
    tick.set_font('Tableau_Book_Regular')  
    tick.set_fontsize(26)

for x,y in zip(g1['Source_Day'],g1['Active']):
    ax2.text(x, y, s=f'{y:.0f} %', transform=ax2.transData,style ='normal',fontweight='bold',fontsize = 26,ha='center',va='top',c='#e9c48f')

fig.savefig(f'x.png', dpi=600,bbox_inches='tight') 

manager df

0 Answers0