怎么在matplotlib中绘图样式

  介绍

这篇文章将为大家详细讲解有关怎么在matplotlib中绘图样式,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

<强>样式是定义图表可视化外观的配置,它由一组预置的<代码> rcParams> matplotlib>

样式使用方法

样式相关模块为<代码> 风格。

1。显示本机可用样式

<代码> matplotlib.style.available 返回本机可用样式的列表。
列表只读,样式更新后,需要使用<代码> reload_library() 重新加载样式。

拷贝[1]:import  matplotlib.style  as 风格   [2]:拷贝style.available   [2]:   [& # 39;Solarize_Light2& # 39;   ,& # 39;_classic_test_patch& # 39;   ,& # 39;bmh& # 39;   ,& # 39;经典# 39;   ,& # 39;dark_background& # 39;   ,& # 39;快# 39;   ,& # 39;fivethirtyeight& # 39;   ,& # 39;ggplot& # 39;   ,& # 39;灰度# 39;   ,& # 39;seaborn& # 39;   ,& # 39;seaborn-bright& # 39;   ,& # 39;seaborn-colorblind& # 39;   ,& # 39;seaborn-dark& # 39;   ,& # 39;seaborn-dark-palette& # 39;   ,& # 39;seaborn-darkgrid& # 39;   ,& # 39;seaborn-deep& # 39;   ,& # 39;seaborn-muted& # 39;   ,& # 39;seaborn-notebook& # 39;   ,& # 39;seaborn-paper& # 39;   ,& # 39;seaborn-pastel& # 39;   ,& # 39;seaborn-poster& # 39;   ,& # 39;seaborn-talk& # 39;   ,& # 39;seaborn-ticks& # 39;   ,& # 39;seaborn-white& # 39;   ,& # 39;seaborn-whitegrid& # 39;   ,& # 39;tableau-colorblind10& # 39;]

2。显示样式详细设置

<代码> matplotlib.style。图书馆> RcParams> 字典对象也是只读的,更新样式后,需要使用<代码> reload_library() 重新加载样式。

拷贝[6]:,style.library[& # 39;快# 39;】   [6]:   RcParams ({& # 39; agg.path.chunksize& # 39;:, 10000年,   ,,,,& # 39;path.simplify& # 39;:,真的,   ,,,,& # 39;path.simplify_threshold& # 39;:, 1.0})

3。重新加载样式

<代码> matplotlib.style.reload_library() 重新加载样式。

4。使用样式

<代码> matplotlib.style.use(风格)将<代码> matplotlib> 使用默认<代码> 样式可以将样式为恢复到默认样式。
该函数只会更新<代码> 风格中定义的<代码> rcParams> rcParams>

参数<代码> 风格有四种取值:

<李>

<代码> str> 风格。可用> <李>

<代码> dict> rcParams> <李>

<代码>路径> 路径> <李>

<代码>列表> matplotlib> str ,<代码>路径> dict> import  matplotlib.pyplot  as  plt   plt.bar ([1, 2, 3], [1, 2, 3])   plt.show ()

怎么在matplotlib中绘图样式

import  matplotlib.pyplot  as  plt   plt.style.use (& # 39; ggplot& # 39;)   plt.bar ([1, 2, 3], [1, 2, 3])   plt.show ()

怎么在matplotlib中绘图样式

import  matplotlib.pyplot  as  plt   plt.style.use ([& # 39; ggplot& # 39; & # 39; dark_background& # 39;])   plt.bar ([1, 2, 3], [1, 2, 3])   plt.show ()

怎么在matplotlib中绘图样式

import  matplotlib.pyplot  as  plt   plt.subplot (221)   plt.bar ([1, 2, 3], [1, 2, 3])   plt.style.use (& # 39; ggplot& # 39;)   plt.subplot (222)   plt.bar ([1, 2, 3], [1, 2, 3])   plt.style.use(& # 39;灰度# 39;)   plt.subplot (223)   plt.bar ([1, 2, 3], [1, 2, 3])   plt.style.use ([& # 39; ggplot& # 39; & # 39;灰度# 39;])   plt.subplot (224)   plt.bar ([1, 2, 3], [1, 2, 3])   plt.show ()

怎么在matplotlib中绘图样式