I am trying to plot a few plots with secondary y axis in the same row in the loop. I would like them to have only one primary y axis on the left side of the first plot and only one secondary y on the right side of the last plot. So far I managed to accomplish the first thing by sharey = True attribute of subplots but I have trouble with the secondary axis.
for r in df.Category1.sort_values().unique():
dfx = df[df['Category1'] == r]
fig, axes = plt.subplots(1,3, figsize = (14,6), sharey=True)
for (n, dfxx), ax in zip(dfx.groupby("Category2"), axes.flat):
ax1 = sns.barplot(x = dfxx['Month'], y = dfxx['value1'], hue = dfxx['Category3'], ci = None, palette = palette1, ax=ax)
ax2 = ax1.twinx()
ax2 = sns.pointplot(x = dfxx['Month'], y=dfxx['value2'], hue = dfxx['Category3'], ci = None, sort = False, legend = None, palette = palette2)
plt.tight_layout()
plt.show()
So as you can see one iteration of the loop, it has only one primary y axis on the left but secondary appears on each of the plots and I would like it to be consistent for all the plots and appear only once for the most right plot.


