Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display kind="swarm" and kind="point" on the same catplot in Seaborn?

I am trying to display both the means and errors (kind="point") and individual data points (kind="swarm") overlayed on the same catplot in Seaborn.

I have the following code:

sns.catplot(x="Variable_A", y="Dependent_Variable", col="Variable_B", data=LRP_df, kind="swarm", color = "black")

sns.catplot(x="Variable_A", y="Dependent_Variable", col="Variable_B", data=LRP_df, kind="point", color = "red")

sns.despine()

which produces the plots separately:

result of calling catplot

How can I make the two plots sit on the same axes?

Thanks!

like image 644
cheekbonemagazine Avatar asked Oct 29 '25 01:10

cheekbonemagazine


1 Answers

Using a face grid, you can overlay each one by specifying each one with map_dataframe(). The examples in this official reference have been modified. The data is based on sample data.

import seaborn as sns

sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")

g = sns.FacetGrid(exercise, col="kind")
g.map_dataframe(sns.stripplot, x="time", y="pulse", color="black")
g.map_dataframe(sns.pointplot, x="time", y="pulse", color="red")
g.set_axis_labels("time", "pulse")

enter image description here

like image 184
r-beginners Avatar answered Oct 30 '25 16:10

r-beginners



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!