01 ,seaborn 基本设置 :5种风格,刻度线,图位置,子图风格,文字大小,线宽

1 ,画正弦曲线,2 条 : plot

  1. 代码 :
# 正弦曲线
def sinplot(flip=1):
    x = np.linspace(1,10,100)
    plt.plot(x,np.sin(x)*flip)
    plt.plot(x+0.5,np.sin(x)*(flip+0.2))

if __name__ == '__main__':
    sinplot(1)
  1. 结果 :

2 ,背景风格,5 种 : 常用 whitegrid

  1. 5 种风格 :
darkgrid, whitegrid, dark, white, ticks
  1. 默认风格 darkgrid :
sns.set()
sinplot()
  1. whitegrid :

  2. dark :

  3. white :

  4. ticks : 加小刻度线

3 ,刻度线 : sns.despine

  1. spine 使用 : 官网
    1 ,top, right, left, bottom : boolean, optional
    2 ,If True, remove that spine.
    3 ,解释 : True - 去掉边界线
  2. 代码 :
if __name__ == '__main__':
    sns.set_style("whitegrid")
    sinplot()
    sns.despine(top=True, right=True, left=False, bottom=False)
  1. 结果 :

4 ,图与刻度线的距离 : offset

  1. 代码 :
if __name__ == '__main__':
    sns.set_style("whitegrid")
    sinplot()
    sns.despine(offset=10)
  1. 结果 :

5 ,子图风格变换 : with 域

  1. 代码 :
# 正弦曲线
def sinplot(flip=1):
    x1 = np.linspace(1,20,100)
    y1 = np.sin(x1)*flip
    x2 = x1
    y2 = np.sin(x2+1)*(flip+0.5)
    plt.plot(x1,y1)
    plt.plot(x2,y2)

if __name__ == '__main__':
    # 子图 ::
    fig = plt.figure(figsize=(6,3))
    # 画图 1 :
    with sns.axes_style("darkgrid"):
        plt.subplot(2,1,1)
        sinplot()
    # 画图 2 :
    with sns.axes_style("whitegrid"):
        plt.subplot(2, 1, 2)
        sinplot()
    plt.show()
  1. 结果 :

6 ,图像控制 :

  1. 意义 : 改变图像风格
  2. 代码 : sns.set_context(“talk”)
  3. 取值范围 : paper, notebook, talk, poster
  4. 什么都不写 : None
  5. poster :
  6. talk :
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章