Matplotlib所有可用样式

Matplotlib 提供的所有可用样式(style)及其特点介绍:


1. 经典风格

  • classic:Matplotlib 旧版的默认风格,颜色较淡,线条较细,适合习惯早期 Matplotlib 风格的用户。
  • _classic_test_patch:一个用于测试的经典风格,与 classic 类似,主要用于 Matplotlib 内部测试。

2. 现代流行风格

  • ggplot:模仿 R 语言的 ggplot2 主题,使用柔和的颜色,带有网格线,适用于数据分析和统计图表。
  • fivethirtyeight:模仿 FiveThirtyEight 网站的数据可视化风格,线条较粗,颜色鲜明,背景为浅灰色,适合数据新闻或高对比度展示。
  • bmh(Bayesian Methods for Hackers):
    • 适合统计分析,背景较浅,网格线清晰,线条较粗。
    • 适用于数据科学、统计建模和机器学习可视化。
  • fast
    • 牺牲部分视觉效果,提升渲染速度,适用于大规模数据集的快速可视化。

3. 深色主题

  • dark_background
    • 黑色背景,适合夜间模式或需要高对比度的可视化展示。
    • 适用于投影仪演示或屏幕展示。
  • seaborn-v0_8-dark
    • Seaborn 主题,深色背景,适合夜间模式的可视化。
  • seaborn-v0_8-dark-palette
    • 深色背景,搭配 Seaborn 颜色方案,颜色较丰富,适合数据展示。
  • seaborn-v0_8-darkgrid
    • 深色背景 + 网格线,适用于数据趋势分析。

4. 浅色主题

  • seaborn-v0_8-white
    • 纯白背景,无网格线,适合简洁风格。
  • seaborn-v0_8-whitegrid
    • 白色背景,带网格线,适合统计数据可视化。

5. 论文、报告风格

  • seaborn-v0_8-paper
    • 适用于学术论文格式,配色简洁,适合黑白打印。
  • seaborn-v0_8-notebook
    • 适用于 Jupyter Notebook 环境,可读性强。
  • seaborn-v0_8-poster
    • 适用于海报或大屏幕展示,字号较大,线条较粗。
  • seaborn-v0_8-talk
    • 适用于演讲或 PPT 展示,增强了对比度和字体大小。

6. 适合出版或色盲友好的风格

  • grayscale
    • 所有颜色变成灰阶,适合黑白打印或研究色彩对比。
  • tableau-colorblind10
    • 适用于色盲用户的 Tableau 颜色方案,提高可读性。

7. Seaborn 主题系列

这些风格都属于 Seaborn 主题,可用于增强 Matplotlib 的可视化美观性:

  • seaborn-v0_8(默认 Seaborn 主题)。
  • seaborn-v0_8-bright(明亮色彩)。
  • seaborn-v0_8-colorblind(色盲友好)。
  • seaborn-v0_8-deep(更深的颜色)。
  • seaborn-v0_8-muted(柔和色调)。
  • seaborn-v0_8-pastel(淡色)。
  • seaborn-v0_8-ticks(适用于带刻度的图表)。

示例:对比不同风格

你可以使用以下代码来快速查看不同风格的效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

styles = ['ggplot', 'fivethirtyeight', 'seaborn-v0_8-darkgrid', 'dark_background']

for style in styles:
plt.style.use(style)
plt.figure()
plt.plot(x, y, label=f"Style: {style}")
plt.legend()
plt.title(f"Matplotlib Style: {style}")
plt.show()
作者

Ethan Wilkins

发布于

2025-03-12

更新于

2025-03-12

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.