0

I am trying to combine a line plot and bar plot in seaborn. Code is as below:)

fig, ax1 = plt.subplots(figsize=(10,6))
sns.barplot(x=df_mergedpa['Day'], y=df_mergedpa['pro_mean'],hue=df_mergedpa['Strain'], ax=ax1)
ax2 = ax1.twinx()
sns.lineplot(x=df_mergedpa['Day'],y=df_mergedpa['ami_mean'],hue=df_mergedpa['Strain'], 
marker='o',  ax=ax1)

The plot I am getting is as above: enter image description here

Why the line plot is not rendering properly. It is extending in X-Axis. I am not able to figure out why?

Dataframe looks as below:

enter image description here

  • Without any access to your data, as you did not provide it, my guess is that one of the x values used in the graph is a string and the other is an int – Michael S. Aug 07 '22 at 13:27
  • Please supply (a sample of) the data from your df so we can reproduce the issue. Use `df_mergedpa.to_dict()` and assign the result to a var (`data = ...` ). – ouroboros1 Aug 07 '22 at 13:27
  • Hi, i have added format of my dataframe. Both line plot and bar plot are using the same column for X axis. – Avnish Jain Aug 07 '22 at 13:33

0 Answers0