1 ,畫正弦曲線,2 條 : plot
- 代碼 :
# 正弦曲線
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)
- 結果 :
2 ,背景風格,5 種 : 常用 whitegrid
- 5 種風格 :
darkgrid, whitegrid, dark, white, ticks
- 默認風格 darkgrid :
sns.set()
sinplot()
-
whitegrid :
-
dark :
-
white :
-
ticks : 加小刻度線
3 ,刻度線 : sns.despine
- spine 使用 : 官網
1 ,top, right, left, bottom : boolean, optional
2 ,If True, remove that spine.
3 ,解釋 : True - 去掉邊界線 - 代碼 :
if __name__ == '__main__':
sns.set_style("whitegrid")
sinplot()
sns.despine(top=True, right=True, left=False, bottom=False)
- 結果 :
4 ,圖與刻度線的距離 : offset
- 代碼 :
if __name__ == '__main__':
sns.set_style("whitegrid")
sinplot()
sns.despine(offset=10)
- 結果 :
5 ,子圖風格變換 : with 域
- 代碼 :
# 正弦曲線
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()
- 結果 :
6 ,圖像控制 :
- 意義 : 改變圖像風格
- 代碼 : sns.set_context(“talk”)
- 取值範圍 : paper, notebook, talk, poster
- 什麼都不寫 : None
- poster :
- talk :