Day04-1画图 Seaborn

seaborn封装了 mayplotlib  可以更方便的进行绘图

import seaborn as sns
import matplotlib.pyplot as plt
import  numpy as np
def sinplot(flip=1):
   x=np.linspace(0,14,100)#在0-14上面找100个点
   for i in range(1,7):
       plt.plot(x,np.sin(x+i*.5)*(7-i)*flip)
   plt.show()
sinplot()

sns.set()#用seaborn 默认的风格
sinplot()

seaborn中的五种主题风格

darkgrid whitegrid

dark white 相对于上一行中grid去掉了横线

ticks带上了数值对应的锯齿

sns.despine() 可以去掉上右的横线

sns.despine(offset=20)设置数据值与图的距离

sns.despine(left=True)隐藏左面的轴

使用with控制子图的两种不同风格

data = np.random.normal(size=(20, 6))
sns.set_style('whitegrid')
sns.boxplot(data=data)
<matplotlib.axes._subplots.AxesSubplot at 0x1fbc03d6780>

png

sns.set_style('dark')
sinplot()

png

sns.set_style('white')
sinplot()

png

sns.set_style('ticks')
sinplot()

png

Remove axes spines

有时候我们会去掉box的上轴和右轴:

sinplot()
sns.despine()

png

当然你也可以:

sns.set_style('white')
sinplot()
sns.despine(left=True, bottom=True)

png

sns.despine()函数默认删除右轴和上轴。

f, ax = plt.subplots()
sns.violinplot(data=data)
<matplotlib.axes._subplots.AxesSubplot at 0x1fbc05bdc18>

png

f, ax = plt.subplots()
sns.violinplot(data=data)
sns.despine(trim=True)

png

Temporarily setting figure style

我们可以临时定义作图参数让子图拥有不同的样式:

with sns.axes_style('darkgrid'):
    plt.subplot(211)
    sinplot()
plt.subplot(212)
sinplot(-1)

png

这样,我们就临时调用了'darkgrid'样式。

 

Seaborn预设了四种比例,根据大小依次为 papernotebooktalk 和 poster。默认为 notebook

sns.set_context('talk')
sinplot()

png

sns.set_context("poster")
sinplot()

png

sns.set_context(font_scale=3.5)可以设置数轴的数字大小

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值