'Adding secondary y-axis with Facetgrid on Seaborn

I have a cohorted dataset (from 1 day to 365 days) that now I am representing like this in Seaborn. The blue line is the previous result, the orange is the current result and the bars are the delta in % between them:

enter image description here

However, I need to add the bars on the same plot that the lineplot with a secondary axis.

My expected output would be this for each plot of the Facetgrid:

enter image description here

A sample of the dataframe that I am using on wide format that I splited in two to separate the date from de delta and the pre y post results. I need it this way because of the cohorted data:

enter image description here

And this is the code I use to plot the first graph:

fig, ax1 = plt.subplots() # initializes figure and plots

ax2 = ax1.twinx() # applies twinx to ax2, which is the second y axis. 

g = sns.FacetGrid(df_ads_long_st, col="m", hue="status", height=5, aspect=0.8)
g.map(sns.lineplot, "dx", "value_a", alpha=.7, ax = ax1)

g = sns.FacetGrid(df_ads_long_de, col="m", hue="status", height=5, aspect=0.8)
g.map(sns.barplot, "dx", "value_a", alpha=.7, ax = ax2)

# these lines add the annotations for the plot. 
ax1.set_xlabel('DX')
ax1.set_ylabel('ARPU', color='b')
ax2.set_ylabel('Delta', color='r')

plt.show(); # shows the plot. 

Is there any other day to do this?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source