python可视化stackplot函数用法-绘制堆积面积图。

matplotlib.pyplot.stackplot(x, *args, labels=(), colors=None, baseline=’zero’, data=None, **kwargs)
堆栈图的思想是随着时间的推移显示“部分到整体”。它用于表示各种数据集而不会彼此重叠。
Stackplot用于绘制堆积面积图。它显示完整的数据以进行可视化。它显示了每个零件相互堆叠以及每个零件如何构成完整的图形。它显示数据的各种组成部分,其行为类似于饼图。它具有x-label,y-label和标题,其中各个部分可以用不同的颜色表示。
在这里插入图片描述
效果如图展示:
在这里插入图片描述
源码附上:

import matplotlib.pyplot as plt

# List of Days
days = [1, 2, 3, 4, 5]

# No of Study Hours
Studying = [7, 8, 6, 11, 7]

# No of Playing Hours
playing = [8, 5, 7, 8, 13]

# Stackplot with X, Y, colors value
plt.stackplot( days, Studying, playing,
               colors=['r', 'c'] )

# Days
plt.xlabel( 'Days' )

# No of hours
plt.ylabel( 'No of Hours' )

# Title of Graph 
plt.title( 'Representation of Study and \
Playing wrt to Days' )

# Displaying Graph
plt.show()

范例#2:使用Stackplot
源码附上:

import matplotlib.pyplot as plt

# List of 7-days
days = [x for x in range( 0, 7 )]

# List of Suspected cases
Suspected = [12, 18, 35, 50, 72, 90, 100]

# List of Cured Cases
Cured = [4, 8, 15, 22, 41, 55, 62]

# List of Number of deaths
Deaths = [1, 3, 5, 7, 9, 11, 13]

# Plot x-labels, y-label and data
plt.plot( [], [], color='blue',
          label='Suspected' )
plt.plot( [], [], color='orange',
          label='Cured' )
plt.plot( [], [], color='brown',
          label='Deaths' )

# Implementing stackplot on data
plt.stackplot( days, Suspected, Cured,
               Deaths, baseline='zero',
               colors=['blue', 'orange',
                       'brown'] )

plt.legend()

plt.title( 'No of Cases' )
plt.xlabel( 'Day of the week' )
plt.ylabel( 'Overall cases' )

plt.show()

输出:
如果基线值设置为零,则下面的图表表示输出
在这里插入图片描述

原文链接:https://vimsky.com/examples/usage/matplotlib-pyplot-stackplot-in-python.html

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值