seaborn內(nèi)置了十幾個示例數(shù)據(jù)集,通過load_dataset函數(shù)可以調(diào)用。其中包括常見的泰坦尼克、鳶尾花等經(jīng)典數(shù)據(jù)集。
作者:Python課堂來源:今日頭條|2020-08-10 06:16
內(nèi)置示例數(shù)據(jù)集
seaborn內(nèi)置了十幾個示例數(shù)據(jù)集,通過load_dataset函數(shù)可以調(diào)用。其中包括常見的泰坦尼克、鳶尾花等經(jīng)典數(shù)據(jù)集。
# 查看數(shù)據(jù)集種類 import seaborn as sns sns.get_dataset_names()
import seaborn as sns # 導(dǎo)出鳶尾花數(shù)據(jù)集 data = sns.load_dataset('iris') data.head()
1. 散點圖
函數(shù)sns.scatterplot
import seaborn as sns sns.set() import matplotlib.pyplot as plt %matplotlib inline # 小費數(shù)據(jù)集 tips = sns.load_dataset('tips') ax = sns.scatterplot(x='total_bill',y='tip',data=tips) plt.show()
2. 條形圖
函數(shù)sns.barplot顯示數(shù)據(jù)平均值和置信區(qū)間
import seaborn as sns sns.set() import matplotlib.pyplot as plt %matplotlib inline # 小費數(shù)據(jù)集 tips = sns.load_dataset("tips") ax = sns.barplot(x="day", y="total_bill", data=tips) plt.show()
3. 線型圖
函數(shù)sns.lineplot繪制折線圖和置信區(qū)間
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. 箱線圖
函數(shù)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. 直方圖
函數(shù)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. 熱力圖
函數(shù)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. 散點圖矩陣
函數(shù)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. 分類散點圖
函數(shù)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. 計數(shù)條形圖
函數(shù)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. 回歸圖
函數(shù) seaborn.lmplot繪制散點及回歸圖
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()
聯(lián)系客服