天天看點

用python的seaborn庫畫柱狀圖plt.bar()

Matplotlib中畫的柱狀圖(左),seaborn中華的柱狀圖(右)

用python的seaborn庫畫柱狀圖plt.bar()
用python的seaborn庫畫柱狀圖plt.bar()

plt.bar()

與matplotlib差別 : 多了sns.set()指令

import seaborn as sns
%matplotlib inline

sns.set()
plt.bar([1,2,3,4,5],[1,3,1,5,6])
           

sns.set()

  • sns.set(style = 'whitegrid')

    有darkgrid,whitegrid,dark, white, ticks參數
sns.set(style = 'whitegrid') #darkgrid,whitegrid,dark, white, ticks
plt.bar([1,2,3,4,5],[1,3,1,5,6])
           
用python的seaborn庫畫柱狀圖plt.bar()
  • sns.despine()

    # 去除圖脊,預設上邊和右邊

    有left, right, top, bottom參數

sns.set(style = 'white')  #darkgrid,whitegrid,dark, white, ticks
plt.bar([1,2,3,4,5],[1,3,1,5,6])
sns.despine()  
           
用python的seaborn庫畫柱狀圖plt.bar()
sns.set(style = 'white')  
plt.bar([1,2,3,4,5],[1,3,1,5,6])
sns.despine(left = True,bottom = True) 
           
用python的seaborn庫畫柱狀圖plt.bar()
  • sns.set_context()

    有paper, notebook, talk, poster參數
plt.rcParams['font.family']='SimHei'#'SimHei'為黑體
plt.rcParams['axes.unicode_minus'] = False #顯示負号

sns.set_context("notebook")# paper, notebook, talk, poster
plt.bar([1,2,3,4,5],[1,3,1,5,6])
plt.title("柱狀圖")
           

參數為paper(左)和notebook(右)的對比圖

用python的seaborn庫畫柱狀圖plt.bar()
用python的seaborn庫畫柱狀圖plt.bar()

繼續閱讀