Seaborn基础

一、导包

import matplotlib.pyplot as plt

import seaborn as sns

二、参数

sns.set(context='notebook',style='darkgrid',palette='deep',font='sans-serif',font_scale=1,color_codes=True)

1、context='':参数控制着默认的画幅大小,分别有 {paper, notebook, talk, poster} 四个值。其中,poster > talk > notebook > paper。

2、style='':参数控制默认样式,分别有 {darkgrid, whitegrid, dark, white, ticks},你可以自行更改查看它们之间的不同。默认是darkgrid

3、palette='':参数为预设的调色板。分别有 {deep, muted, bright, pastel, dark, colorblind} 等,你可以自行更改查看它们之间的不同。

4、font='' 用于设置字体。font_scale= '':设置字体大小。color_codes='': 不使用调色板而采用先前的 'r' 等色彩缩写。

5、seaborn是绘制风格,需要绘图语句之前设置,否则无效。

三、despine()函数移除坐标轴

sns.despine()函数默认移除了上部和右侧的轴,当然我们也可以移除其他轴。

对于是否移除某个轴,我们可以设置sns.despine()函数的top、right、left、bottom参数的值来控制,值为True时,会移除该轴,反之,保留该轴。

四、使用with设置风格,在with下画的图都可以使用该种风格

def sinplot():

    x = np.linspace(0, 15, 100)

    for i in range(1, 3):

        plt.plot(x, np.sin(x + i))

# 设置子图风格

with sns.axes_style("darkgrid"):

    plt.subplot(211)   #with语句块下使用darkgrid风格

    sinplot()

 plt.subplot(212)  #不在with语句块下使用默认的white风格

 sinplot()

五、调色板

import seaborn as sns

1、#hls调用调色板

sns.palplot( sns.color_palette(hls,颜色数))  #用的是RGB的值。

2、# 获取默认调色板的颜色列表

current_palette = sns.color_palette()

3、# 绘制调色板的颜色

sns.palplot(current_palette)

theme_list=['deep', 'muted', 'pastel','bright', 'dark', 'colorblind']

for i in theme_list:

    sns.palplot(sns.color_palette(i))

4、使用调色板

import matplotlib.pyplot as plt

import seaborn as sns

x=[]

y=[]

plt.figure(figsize=(20,8),dpi=80)

colors=sns.color_palette('hls',len(x))

plt.bar(x,y,color=colors)

plt.show()

你可能感兴趣的:(Seaborn基础)