0

I am trying to create a simple subplot in seaborn using 1 row 2 columns. But am not getting the expected result. Instead my figures are displaying separately. Please help.

df = sns.load_dataset("tips")
fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (15,6))
sns.relplot(x = "tip", y= "total_bill" , data = df , hue = "smoker", kind = "line", 
        hue_order = ["No", "Yes"], ax = axes[0])
sns.catplot(x = "tip", data = df, kind = "point", ax = axes[1])

Result

Redox
  • 9,321
  • 5
  • 9
  • 26

1 Answers1

1

Both the plots you are using - relplot and catplot are figure level plots. They cannot be used as sub plots. That is the reason you are seeing the initial blank plots and then the individual relplot and catplot.

You need to use lineplot and pointplot respectively instead, which will allow you to use the subplots. Note that kind='line' is no longer required, so it has been commented out in the code below...

df = sns.load_dataset("tips")
fig, axes = plt.subplots(nrows = 1, ncols = 2, figsize = (15,6))
sns.lineplot(x = "tip", y= "total_bill" , data = df , hue = "smoker", #kind = "line", 
        hue_order = ["No", "Yes"], ax = axes[0])
sns.pointplot(x = "tip", data = df, kind = "point", ax = axes[1])

Plot

enter image description here

Redox
  • 9,321
  • 5
  • 9
  • 26