zoukankan      html  css  js  c++  java
  • Matplotlib 风格样式

    matplotlib中提供了许多整体的风格样式以供我们选择。

    >>> plt.style.available
    
    ['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']

    接下来就展示一下其中的一些风格,基于此设计了一个可以绘制直方图和正弦余弦曲线的函数,然后使用with的上下文管理器语法,测试不同的风格:

    def hist_and_lines():
        np.random.seed(10)
        fig, ax = plt.subplots(1, 2, figsize=(11, 4))
        ax[0].hist(np.random.randn(1000))
        x = np.linspace(0,10,100)    
        ax[1].plot(np.sin(x))
        ax[1].plot(np.cos(x))
        ax[1].legend(['a', 'b', 'c'], loc='lower left')

    with语句:

    with plt.style.context('classic'):
        hist_and_lines()
    plt.show()

    将其中的‘classic’字符串替换成你想要的风格名称,就能在with管理区内使用风格,而不影响后面的绘图。

    • 默认风格classic

    • fivethirtyeight

    • ggplot

    • 灰度grayscale

    • seaborn

    matplotlib中支持的风格样式共有二十多种,这里只是选出几种来作为展示,具体可以自行选择。

  • 相关阅读:
    C# 访问USB(HID)设备
    IPad C盘中backup文件夹占用太多空间
    fastboot
    adb get android's ip
    Reading MMS
    Bitcoin
    内存问题导致编译不过!
    串口LOG 单编kernel
    Source Insight 格式化
    framework层的空指针会让系统重启
  • 原文地址:https://www.cnblogs.com/lavender1221/p/12806915.html
Copyright © 2011-2022 走看看