Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Display the number of observations inside a Seaborn boxplot

import matplotlib.pyplot as plt
import seaborn as sns
df = sns.load_dataset("iris")
ax = sns.boxplot(y="species", x="sepal_length", data=df) 
medians = df.groupby(['species'])['sepal_length'].median().values
nobs = df['species'].value_counts().values
nobs = [str(x) for x in nobs.tolist()]
nobs = ["n: " + i for i in nobs] 
pos = range(len(nobs))
for tick,label in zip(pos,ax.get_yticklabels()):
    ax.text(medians[tick],tick,nobs[tick],color='black', verticalalignment = "bottom")
sns.despine()
plt.show();
Comment

PREVIOUS NEXT
Code Example
Python :: softmax for nparray 
Python :: membuat chat bot dengan python 
Python :: how to capture multiple screens with ImageGrab 
Python :: flask buildspec.yml 
Python :: How to get a mock image in django? 
Python :: pep8 E302 
Python :: OpenCV(3.4.11) Error: Assertion failed (_img.rows * _img.cols == vecSize) in CvCascadeImageReader::PosReader::get 
Python :: how to send more than one variables to python using xlwings 
Python :: Which of the following statements is used to create an empty set in Python? 
Python :: Replace u00a0 
Python :: pagerank formula 
Python :: how to make a square shape in python 
Python :: violin plot seaborn 
Python :: The print() Function 
Python :: ladnha; 
Python :: cannot access modules from neighbouring directories jupyter notebook 
Python :: python time a code segment 
Python :: simplejwt in django setup 
Python :: how to remove no data times plotly 
Python :: python group groupe of 2 
Python :: color to black and white opencv 
Python :: jupiter output 
Python :: crop image using opencv with height and width 
Python :: make a coo_matrix 
Python :: python open file partially 
Python :: abstract user in django 
Python :: python redirect console output to devnull 
Python :: how to loop through a list from the last element in python 
Python :: python wikipedia 
Python :: python transpose a list 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =