Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seaborn pointplot above swarmplot

I try to plot group wise median values using seaborn's pointlot on top of a swarmplot. Even though I call pointPlot second, the point plot ends up behind the swarmplot. How can I change the 'layer order' such that the point plot is in front of the swarmplot?

datDf=pd.DataFrame({'values':np.random.randint(0,100,100)})
datDf['group']=np.random.randint(0,5,100)
sns.swarmplot(data=datDf,x='group',y='values')
sns.pointplot(data=datDf,x='group',y='values',estimator=np.median,join=False)

enter image description here

like image 750
jlarsch Avatar asked May 05 '17 07:05

jlarsch


People also ask

What is Pointplot in seaborn?

Show point estimates and confidence intervals using scatter plot glyphs. A point plot represents an estimate of central tendency for a numeric variable by the position of scatter plot points and provides some indication of the uncertainty around that estimate using error bars.

How do you plot more than one graph in seaborn?

In Seaborn, we will plot multiple graphs in a single window in two ways. First with the help of Facetgrid() function and other by implicit with the help of matplotlib. data: Tidy dataframe where each column is a variable and each row is an observation.

Is seaborn built on top of Matplotlib?

Seaborn is a high-level library. It provides simple codes to visualize complex statistical plots, which also happen to be aesthetically pleasing. But Seaborn was built on top of Matplotlib, meaning it can be further powered up with Matplotlib functionalities.

What is seaborn Swarmplot?

Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn. swarmplot() is used for this. Let's say the following is our dataset in the form of a CSV file − Cricketers.csv. At first, import the required 3 libraries −


1 Answers

Use zorder property to set proper drawing order.

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pylab as plt

datDf=pd.DataFrame({'values':np.random.randint(0,100,100)})
datDf['group']=np.random.randint(0,5,100)
sns.swarmplot(data=datDf,x='group',y='values',zorder=1)
sns.pointplot(data=datDf,x='group',y='values',estimator=np.median,join=False, zorder=100)
plt.show()

enter image description here

like image 150
Serenity Avatar answered Sep 28 '22 08:09

Serenity