Home > Enterprise >  Seaborn to create two lineplots from different dataframes, reusing these plots in several chunks, an
Seaborn to create two lineplots from different dataframes, reusing these plots in several chunks, an

Time:02-05

From this enter image description here

Any help is appreciated. If the full df is needed, I can edit this question.

CodePudding user response:

the idea is to have 1 figure with 2 subplots. so that call to plt.subplots() should only be done once, and your plots need to reference the output of that.

this is the kind of thing you need to do:

fig, ax = plt.subplots(1,2)  # only do this 1x 

sns.lineplot(x="time", 
             y="value", 
             hue = "Group",
             ci=90, err_style='bars',
             data=df_long, ax=ax[0])  # use this as 1st plot in `fig`
ax[0].set(xlabel = "Time", ylabel = "Result")
ax[0].set_title('Trajectory of depression during the pandemic', size=20)

sns.lineplot(x="time", 
             y="value", 
             hue = "Group",
             ci=90, err_style='bars',
             data=df_long2, ax=ax[1])  # use this as 2nd plot in `fig`
ax[1].set(xlabel = "Time", ylabel = "Result")
ax[1].set_title('Trajectory of anxiety during the pandemic', size=20)

plt.show()
  •  Tags:  
  • Related