使用Python绘制堆积面积图

使用Python绘制堆积面积图

  • 堆积面积图
  • 效果
  • 代码

堆积面积图

堆积面积图是面积图的一种扩展,通过堆积多个区域展示不同类别数据的累积变化。常用于显示不同部分对整体的贡献。

效果

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pQbW4Fbd-1720675937351)(https://i-blog.csdnimg.cn/direct/4b22181bcb334d079a40dac13fb55b1f.png)]

代码

import matplotlib.pyplot as plt
from pylab import *
mpl.rcParams['font.sans-serif']=['SimHei']
# 示例数据
years = [2015, 2016, 2017, 2018, 2019]
category1 = [10, 15, 20, 25, 30]
category2 = [5, 10, 15, 20, 25]

# 绘制堆积面积图
plt.fill_between(years, category1, color="skyblue", alpha=0.4)
plt.fill_between(years, [i+j for i, j in zip(category1, category2)], category1, color="lightgreen", alpha=0.4)

# 设置标签和标题
plt.xlabel('Year')
plt.ylabel('Value')
plt.title('堆积面积图')

plt.show()

相关推荐

  1. 使用Python绘制堆积面积

    2024-07-11 14:40:06       10 阅读
  2. 使用Python绘制百分比堆积条形

    2024-07-11 14:40:06       11 阅读
  3. 使用Python绘制百分比堆积柱形

    2024-07-11 14:40:06       10 阅读
  4. 使用Python绘制旭日

    2024-07-11 14:40:06       11 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 14:40:06       8 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 14:40:06       8 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 14:40:06       7 阅读
  4. Python语言-面向对象

    2024-07-11 14:40:06       10 阅读

热门阅读

  1. React@16.x(53)Redux@4.x(2)- action

    2024-07-11 14:40:06       10 阅读
  2. TS-类型别名和接口的区别

    2024-07-11 14:40:06       9 阅读
  3. 索引

    2024-07-11 14:40:06       8 阅读
  4. 嵌入式Bootloader面试题面面观(2万字长文)

    2024-07-11 14:40:06       12 阅读
  5. 1.python基础

    2024-07-11 14:40:06       10 阅读
  6. 24/07/11数据结构(6.1215)双链表实现-栈实现

    2024-07-11 14:40:06       10 阅读