1.小提琴图。
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p1=sns.violinplot( y=df["sepal_length"] )
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p2=sns.violinplot( x=df["species"], y=df["sepal_length"] )
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p1=sns.violinplot( y=df["species"], x=df["sepal_length"] )
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p1=sns.violinplot( x=df["species"], y=df["sepal_length"], linewidth=5)
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p3=sns.violinplot( x=df["species"], y=df["sepal_length"], width=0.3)
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p1=sns.violinplot( x=df["species"], y=df["sepal_length"], palette="Blues")
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
my_pal = {"versicolor": "g", "setosa": "b", "virginica":"m"}
p3=sns.violinplot( x=df["species"], y=df["sepal_length"], palette=my_pal)
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
my_pal = {species: "r" if species == "versicolor" else "b" for species in df.species.unique()}
p4=sns.violinplot( x=df["species"], y=df["sepal_length"], palette=my_pal)
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('tips')
p1=sns.violinplot(x="day", y="total_bill", hue="smoker", data=df, palette="Pastel1")
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
p1=sns.violinplot(x='species', y='sepal_length', data=df, order=[ "versicolor", "virginica", "setosa"])
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
my_order = df.groupby(by=["species"])["sepal_length"].median().iloc[::-1].index
p2=sns.violinplot(x='species', y='sepal_length', data=df, order=my_order)
plt.show()
import matplotlib.pylab as plt
import seaborn as sns
df = sns.load_dataset('iris')
ax = sns.violinplot(x="species", y="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_xticklabels()):
ax.text(pos[tick], medians[tick] + 0.03, nobs[tick],
horizontalalignment='center', size='x-small', color='w', weight='semibold')
plt.show()
本博主新开公众号, 希望大家能扫码关注一下,十分感谢大家。
本文来自:https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py