import seaborn as sns
%matplotlib inline
import numpy as np
#显示调用set()获取默认绘图
sns.set()
np.random.seed(0)
arr = np.random.randn(100)
ax = sns.displot(arr,bins=10)
arr_random = np.random.randint(0,100,500)
sns.displot(arr_random,rug=True)
import pandas as pd
dataframe_obj = pd.DataFrame({"x":np.random.randn(500),
"y":np.random.randn(500)})
dataframe_obj
x | y | |
---|---|---|
0 | -0.142159 | 0.251125 |
1 | -1.242701 | 2.350381 |
2 | -0.077052 | -1.341755 |
3 | -0.152082 | 1.406249 |
4 | -1.164122 | -0.326396 |
5 | 0.830591 | 1.357825 |
6 | -0.529517 | 1.563868 |
7 | 0.814794 | -1.379856 |
8 | 1.270501 | -1.119632 |
9 | 0.348622 | -2.592021 |
10 | 1.296603 | -2.004974 |
11 | 0.381616 | 0.367991 |
12 | -0.559310 | -0.555308 |
13 | -1.379021 | -0.647064 |
14 | -0.095165 | -0.507545 |
15 | 0.338139 | -1.498163 |
16 | -0.550371 | -1.943398 |
17 | -0.835802 | 0.621729 |
18 | 0.068743 | -0.096514 |
19 | -0.186162 | 1.301902 |
20 | -0.076112 | -1.042048 |
21 | -1.163619 | -1.310745 |
22 | 0.795033 | 0.884682 |
23 | -0.150551 | -0.201355 |
24 | 0.549732 | 0.522551 |
25 | 0.459072 | 0.379233 |
26 | 0.113401 | 0.412743 |
27 | 0.736626 | -0.462511 |
28 | 1.224755 | -0.761993 |
29 | -0.190695 | -0.035088 |
... | ... | ... |
470 | 0.056792 | 0.396389 |
471 | 0.183469 | -1.440152 |
472 | 0.973002 | -0.616674 |
473 | -0.766647 | -0.797700 |
474 | -1.030069 | -0.215906 |
475 | -0.039692 | 0.468480 |
476 | 0.227015 | -1.850117 |
477 | 0.280432 | 0.254587 |
478 | 0.320348 | 1.745545 |
479 | -0.274694 | -1.601397 |
480 | -1.844971 | 0.620336 |
481 | 0.094218 | -0.585577 |
482 | 0.214926 | -0.534442 |
483 | -1.007970 | -0.324485 |
484 | 0.251730 | 1.230667 |
485 | 0.829316 | -1.149112 |
486 | 1.990679 | 0.956896 |
487 | -1.046122 | 0.417126 |
488 | -0.884596 | 0.170513 |
489 | 0.796083 | 0.434371 |
490 | 0.531118 | -0.422780 |
491 | -0.311346 | 0.641749 |
492 | 0.717745 | -1.871190 |
493 | 0.889632 | -0.590539 |
494 | 0.232941 | 0.756412 |
495 | 2.054601 | 0.821175 |
496 | -1.266659 | 1.676193 |
497 | -1.610574 | -0.993553 |
498 | -1.328470 | 0.856041 |
499 | -0.187035 | -0.162609 |
500 rows × 2 columns
#散布图
sns.jointplot(x='x',y='y',data = dataframe_obj)
#二维直方图
sns.jointplot(x='x',y='y',data=dataframe_obj,kind='hex')
#核密度估计
sns.jointplot(x="x",y="y",data=dataframe_obj,kind="kde")
<seaborn.axisgrid.JointGrid at 0x1480bdf7e48>
dataset = sns.load_dataset("tips")
sns.pairplot(dataset)
#用分类数据绘图
tips = sns.load_dataset("tips")
sns.stripplot(x = "day",y="total_bill",data=tips)
#用分类数据绘图
tips = sns.load_dataset("tips")
sns.stripplot(x = "day",y="total_bill",data=tips,jitter = True)
sns.swarmplot(x='day',y='total_bill',data=tips)
sns.boxplot(x='day',y='total_bill',data=tips)
sns.violinplot(x='day',y='total_bill',data=tips)
sns.barplot(x='day',y='total_bill',data=tips)
sns.pointplot(x='day',y='total_bill',data=tips)