How to plot two joyplots on the same plot?

602 Views Asked by At

I want to create ridgelines plots for the distribution of property Rg as it changes with temperature. It turns out that I have an attribute Z that changes too, so I want the distribution of Rg at a given condition, for both attributes Z1 and Z2. I want the ridgeline plots to be side by side. This is what I have so far:

import pandas as pd
import numpy as np 
import matplotlib.pyplot as plt 
import joypy as j
from joypy import joyplot 
import seaborn as sns

df_iso = pd.DataFrame(data=d_iso)
df_atac = pd.DataFrame(data=d_atac)

plt.figure() 
joyplot(data=df_iso[['temperature', 'Rg']], by='temperature', column='Rg', figsize=(12, 8))
joyplot(data=df_atac[['temperature', 'Rg']], by='temperature', column='Rg', figsize=(12, 8))
plt.title('Ridgeline plot of Rg histograms')
plt.show()

My plots look like this: enter image description here

I want them to be on the same plot, with different colors and legends for each color.

How can I go about this? Any advice you have would be appreciated.

1

There are 1 best solutions below

0
Paul Liu On

You shall merge the two dataframes by merge. And include another column to plot. That would be work

df_iso = pd.DataFrame(data=d_iso)
df_atac = pd.DataFrame(data=d_atac)
dfMerge = pd.merge(df_iso[['temperature']], df_atac[['temperature']], right_on='temperature')
plt.figure() 
joyplot(data=dfMerge[['temperature', 'Rg']], by='temperature', column='Rg', figsize=(12, 8))
plt.title('Ridgeline plot of Rg histograms')
plt.show()