I am trying to plot a line plot over a bar plot and cannot get the line plot to render with the bar chart. I can render the bar chart all the time and the line only when commenting out ax2. When I do render the line plot the dates show up in integer instead of date format. I think it has something to do with the X axis but cannot figure it out.
fig, ax = plt.subplots(figsize = (10, 10))
ax = sns.lineplot(x='Submission Date', y='Rating', data=df_cd)
ax2 = ax.twinx()
ax2 = sns.barplot(x='Submission Date', y='Count Handled', data=df_cd)
ax.set_xticklabels(ax.get_xticks())
plt.show()


The command plt.subplots(figsize = (10, 10)), indicates that you want to divide canvas and create the subplots on it.
For your current requirement, you could do something like -
ax = sns.barplot(x='Submission Date', y='Count Handled', data=df_cd)
ax2 = ax.twinx()
ax2.plot(ax.get_xticks(), df_cd.Rating)
Here, you are creating the barplot first and adding the line plot over it with the same x-axis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With