Matplotlib使用样式表自定义绘图

使用样式表自定义绘图
style包为易于切换的绘图『样式』增加了支持,它们与matplotlibrc文件参数相同。
他所包含的样式有:‘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’等

调用前五个样式绘图,代码如下:

'''
style:plot_style_sheet
author:Made by Sherlock福尔魔芋
vx:18723584101 
time:2019-11-29
'''
import numpy as np
import matplotlib.pyplot as plt
a=plt.style.available #所有的样式
#print(a)
for i in a[:5]:
    plt.style.use(i)#调用预设样式
    print(plt.style.available)#所有可用的样式
    fig,ax=plt.subplots()#plt.subplots()是一个函数,返回一个包含figure和axes对象的元组。因此,使用fig,ax=plt.subplots()将元组分解为fig和ax两个变量
# 绘图
    L=6
    x=np.linspace(0,L)
    ncolors=len(plt.rcParams['axes.prop_cycle'])
    shift=np.linspace(0,L,ncolors,endpoint=False)
    for s in shift:
        ax.plot(x,np.sin(x+s),'o-')
    ax.set_xlabel('x-axis')
    ax.set_ylabel('y-axis')
    ax.set_title(i+"style sheet")
    plt.show()

bmh样式
classi样式
dark_background样式
fast样式
fivethirtyeight样式

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值