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 :

7 ,文字大小 :font_scale

  1. 代码 :
if __name__ == '__main__':
    # 子图 ::
    fig = plt.figure(figsize=(6,3))
    # 画图 1 :
    sns.set_style("whitegrid")
    sns.set_context("talk",font_scale=1.5)
    sinplot()
    plt.show()
  1. 效果比较 :

8 ,线宽 :

  1. 代码 :
if __name__ == '__main__':
    # 子图 ::
    fig = plt.figure(figsize=(6,3))
    # 画图 1 :
    sns.set_style("whitegrid")
    sns.set_context("talk",font_scale=0.5,rc={"lines.linewidth":4})
    sinplot()
    plt.show()
  1. 结果 :
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值