Last Update:2020-06-29
Source: Internet
Author: User
Keywords
seaborn
seaborn tutorial
seaborn python
Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics.
Built in sample dataset
Seaborn has built-in more than a dozen sample datasets, through the load_ The dataset function can be called.
It includes the classic datasets such as Titanic and iris.
#View dataset types
import seaborn as sns
sns.get_ dataset_ names()
import seaborn as sns
#Export iris data set
data = sns.load_ dataset('iris')
data.head ()
1. Scatter plot
function sns.scatterplot
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
#Tips data set
tips = sns.load_ dataset('tips')
ax = sns.scatterplot (x='total_ bill',y='tip',data=tips)
plt.show ()
2. Bar chart
function sns.barplot
Display data mean and confidence interval
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
#Tip dataset
tips = sns.load_ dataset("tips")
ax = sns.barplot (x="day", y="total_ bill", data=tips)
plt.show ()
3. Line drawing
function sns.lineplot
Draw line chart and confidence interval
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
fmri = sns.load_ dataset("fmri")
ax = sns.lineplot (x="timepoint", y="signal", data=fmri)
plt.show ()
4. Box diagram
function seaborn.boxplot
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_ dataset("tips")
ax = sns.boxplot (x="day", y="total_ bill", data=tips)
plt.show ()
5. Histogram
function seaborn.distplot
import seaborn as sns
import numpy as np
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed (0)
x = np.random.randn (1000)
ax = sns.distplot (x)
plt.show ()
6. Thermograph
function seaborn.heatmap
import numpy as np
np.random.seed (0)
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
uniform_ data = np.random.rand (10, 12)
ax = sns.heatmap (uniform_ data)
plt.show ()
7. Scatter matrix
function sns.pairplot
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
iris = sns.load_ dataset("iris")
ax = sns.pairplot (iris)
plt.show ()
8. Classified scatter plot
function seaborn.catplot
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
exercise = sns.load_ dataset("exercise")
ax = sns.catplot (x="time", y="pulse", hue="kind", data=exercise)\
plt.show ()
9. Counting bar chart
function seaborn.countplot
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
titanic = sns.load_ dataset("titanic")
ax = sns.countplot (x="class", data=titanic)
plt.show ()
10. Regression graph
Function seaborn.lmplot
Drawing scatter and regression map
import seaborn as sns
sns.set ()
import matplotlib.pyplot as plt
%matplotlib inline
tips = sns.load_ dataset("tips")
ax = sns.lmplot (x="total_ bill", y="tip", data=tips)
plt.show ()