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 :
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章