使用样式表自定义绘图
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()