matplotlib.pyplot设置画布主题

import matplotlib.pyplot as plt

# 定义一个画图函数
def sinplot(flip = 1):
    x = np.linspace(0,10,100)
    for i in range(1,4):
        y = np.sin(x + i * 0.5) * (4 - i) * flip
        plt.plot(x, y)

plt.style.available # 获取所有主题,返回一个列表
['Solarize_Light2',
 '_classic_test_patch',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark',
 'seaborn-dark-palette',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'tableau-colorblind10']
styles = plt.style.available

for style in styles:
    plt.style.use(style) # 设置主题
    plt.figure(figsize=(5,5))
    sinplot()
    plt.title(style)
    plt.show()
posted @ 2021-02-23 17:57  世纪小小孟  阅读(594)  评论(0编辑  收藏  举报