风格样式展示

阅读: 4922     评论:1

到现在,我们可以追求一下整体的风格样式了:

>>> 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()

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

  • 默认风格classic

img

真的比较丑,和matlab一样。

  • fivethirtyeight

img

  • ggplot

img

这个风格是模仿R语言的ggplot工具风格。

  • bmh

img

  • 灰度grayscale

比较适合黑白打印的需求

img

  • seaborn

img

这个样式来自Seaborn库。在Jupyter notebook中import seaborn后,会自动加载这个样式。


 自定义坐标轴刻度 下一步 

评论总数: 1


点击登录后方可评论

请问怎么将matplotlib的图像结果输出在html中,和django结合起来?