浅谈在matplotlib中更改plt.plot()的绘图风格

偶然间发现matplotlib中设置样式表(style sheet)的功能,这个函数是plt.style,主要用来选择plot的呈现风格。
废话不多少,先看下效果

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
plt.style.use('dark_background') 
np.random.seed(1)
data = np.random.randn(50)
plt.plot(data)
plt.show()

在这里插入图片描述

来看下有多少个可用的style

print(len(plt.style.available))
print(plt.style.available)

26
[‘bmh’, ‘classic’, ‘dark_background’,‘fast’, ‘fivethirtyeight’, ‘ggplot’, ‘grayscale’, ‘seaborn-bright’,‘seaborn-colorblind’, ‘seaborn-dark-palette’, ‘seaborn-dark’,‘seaborn-darkgrid’, ‘seaborn-deep’, ‘seaborn-muted’, ‘seaborn-notebook’, ‘seaborn-paper’,‘seaborn-pastel’, ‘seaborn-poster’, ‘seaborn-talk’, ‘seaborn-ticks’,‘seaborn-white’, ‘seaborn-whitegrid’, ‘seaborn’, ‘Solarize_Light2’,‘tableau-colorblind10’, ‘_classic_test’]

既然有26种(不过,有很多种没什么区别啦= =!)
接下来逐一试试这些风格

plt.style.use('bmh')  
#也可以使用mpl.style.use(' bmh ')

在这里插入图片描述
plt.style.use(‘classic’)
在这里插入图片描述
plt.style.use(‘dark_background’)
在这里插入图片描述
plt.style.use(‘fast’)
在这里插入图片描述
plt.style.use(‘fivethirtyeight’)
在这里插入图片描述
plt.style.use(‘ggplot’) ##据说是模仿ggplot(R语言的一个的流行绘图包)的美学
在这里插入图片描述
plt.style.use(‘grayscale’)
在这里插入图片描述
plt.style.use(‘seaborn-bright’)
在这里插入图片描述
plt.style.use(‘seaborn-colorblind’)
在这里插入图片描述
plt.style.use(‘seaborn-dark-palette’)
在这里插入图片描述
plt.style.use(‘seaborn-dark’)
在这里插入图片描述
plt.style.use(‘seaborn-darkgrid’)
在这里插入图片描述
plt.style.use(‘seaborn-deep’)
在这里插入图片描述
plt.style.use(‘seaborn-muted’)
在这里插入图片描述
plt.style.use(‘seaborn-notebook’)
在这里插入图片描述
plt.style.use(‘seaborn-paper’)
在这里插入图片描述
plt.style.use(‘seaborn-pastel’)
在这里插入图片描述
plt.style.use(‘seaborn-poster’)
在这里插入图片描述
plt.style.use(‘seaborn-talk’)
在这里插入图片描述
plt.style.use(‘seaborn-ticks’)
在这里插入图片描述
plt.style.use(‘seaborn-white’)
在这里插入图片描述
plt.style.use(‘seaborn-whitegrid’)
在这里插入图片描述plt.style.use(‘seaborn’)
在这里插入图片描述
plt.style.use(‘Solarize_Light2’)
在这里插入图片描述
plt.style.use(‘tableau-colorblind10’)
在这里插入图片描述
plt.style.use(’_classic_test’)
在这里插入图片描述最后可以使用默认格式的
mpl.style.use(‘default’)
在这里插入图片描述
总结以上,

可以使用mpl.style也可以使用plt.style,效果一样;

可以应用 .available 方法查看具体的style名称

感兴趣的可以关注公众号“分享猿”啦~

  • 31
    点赞
  • 105
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值