用 matplotlib能够完成一些基本的图表操作,而 Seaborn 库可以让这些图的表现更加丰富。

1、 import seaborn as sns 

  用于导入 seaborn 库,并取别名为 sns ,后续介绍都用 sns 代表 seaborn 。

2、 sns.set()

  设置画图空间为 Seaborn 默认风格。

3、 sns.set_style( strStyle )

  设置画图空间为指定风格,分别有:

  • darkgrid
  • whitegrid
  • dark
  • white
  • ticks

4、 sns.despine()

  隐藏右边和上边的边框线。

5、 sns.despine( offset = 10 )

  设置纵横两轴近原点端点距离原地的距离。

6、 sns.despine( left = True )

  在隐藏右和上边框线的同时,隐藏左边线。

7、  with sns.axed_style( "darkgrid" ) : 

  此背景风格设置只对冒号后对应缩进内画的图有效,其他区域不变。

8、 sns.color_palette()

  调色板,画图时可以从他的对象中取颜色,不传参的话会取六个默认的颜色循环:deep, muted, pastel, bright, dark, colorblind。

9、 sns.palplot( sns.color_palette( "hls" , 8 ) )

  在 hls 颜色空间中均匀地取八种颜色放入调色盘。

10、 sns.boxplot ( data = data , palette = sns.color_palette ( "hls" , 8 )

  用调色盘画箱线图。

11、 sns.hls_palette( 8 , l = .7 , s = .9)

  用hls_palette() 函数可以在从 hls 颜色空间取颜色时,控制颜色的亮度和饱和度,

  • l-亮度 lightness
  • s-饱和 saturation

12、 sns.color_palette( "Paired" , 10)

  取 10 个, 5 对颜色,都是深浅对应的。

13、 sns.xkcd_rgb[ "pale red" , lw = 3 ]

  使用 xkcd 可以通过颜色名调用颜色,不过这个需要知道颜色名跟颜色的对应关系。

14、sns.color_palette( "Blues" , 8 )

  取颜色由浅到深渐变的 8 种蓝色(变来变去还是蓝色)。

15、 sns.color_palette( "Blues_r" , 8 )

  要取颜色由深到浅的颜色时,只需要在颜色名后面加上  "_r" 就行了。

16、 sns.color_palette( "cubehelix" , 8 )

  取颜色由深到浅线性变换的 8 个颜色(不同的颜色)。

17、 sns.cubehelix_palette( 8 , start = .5 , rot = -.75 )

  完成16的操作的专用函数,根据 start 和 rot 不同的值,可以得到不同的颜色。

18、 sns.light_palette( "green" )

由浅到深的连续渐变调色板。

19、 sns.dark_palette( "green" )

由深到浅的连续渐变调色板。

20、 sns.distplot( x , bins = 20 , kde = False , fit = stats.gamma)

  以 ndarray 类型的 x 作为数据,画柱形图,查看单变量数据分布情况, bins 是将 X 轴上的值分成 20 段 ,画图时统计每一段的值出现的次数

  fit 会画出数据走势线。

21、 sns.jointplot( x = "x" , y = "y" , data = df )

  画出反映两个变量之间关系的散点图,以及各自的柱形图。

 22、 sns.jointplot( x = x , y = y , kind = "hex" , color = "k" )

  当数据量很大时,可以调整 kind 参数为 "hex" ,会用颜色深浅来表示数据分不密度,以此达到观测效果。

23、 sns.pairplot( sns.load_dataset( "iris" ) )

  当有多个变量时,可以用 pairplot 画出各个变量俩俩关系的散点图及各自的柱形图。

24、 sns.regplot( x = ColumnName1 , y = ColumnName2 , data = DataFrame1 )

   sns.lmplot( x = ColumnName1 , y = ColumnName2 , data = DataFrame1 )

   regplot() 和 implot() 都可以绘制线性回归图, lmplot 相比 regplot 更灵活的同时也更复杂。