0

I am working on two figures with 2 axes each.

When I plot the below:

fig, (ax1,ax2) = plt.subplots(nrows=2,ncols=1,figsize=(20,20),sharex=True)
ax1.plot(df_center.index,df_center)
ax2.plot(df_location.index,df_location)

the plot is perfectly fine with the first plot in upper row (axes) and the 2nd plot in second row (axes2) in fig 1

however when I now go for a second figure which uses seaborn I do not get the desired result:

fig2, (ax1,ax2) = plt.subplots(nrows=2, ncols=1,figsize=(20,20))
ax1 = sns.boxplot(data=df_lweek,y="AgegDays",x="center")
ax1 = sns.swarmplot(data=df_lweek,y="AgeDays",x="center",color="black",size=2.5)
ax2 =  sns.scatterplot(data=df_lweek,x="AgeDays",y="ExpMonths",hue="center")

Everything gets plotted in the second row i.e. axes2. Why is the boxplot and swarmplot not getting plotted in the 1st row i.e. axes 1 of fig 2

Sunil
  • 131
  • 1
  • 9

1 Answers1

1

Well it seems that there is a different way of plotting the seaborn plots in axes. After making the below changes it worked:

fig2, (ax1,ax2) = plt.subplots(nrows=2, ncols=1,figsize=(20,20))
sns.boxplot(data=df_lweek,y="AgegDays",x="center",ax=ax1)
sns.swarmplot(data=df_lweek,y="AgeDays",x="center",color="black",size=2.5,ax=ax1)
sns.scatterplot(data=df_lweek,x="AgeDays",y="ExpMonths",hue="center",ax=ax2)
Mr. T
  • 11,960
  • 10
  • 32
  • 54
Sunil
  • 131
  • 1
  • 9