我是靠谱客的博主 无奈画笔,最近开发中收集的这篇文章主要介绍【数据可视化】Stackplot,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Matplotlib.pyplot.stackplot() in Python

Example #1 : Using Stackplot 
The code describes the x-axis as number of days from Monday to Friday while Y-axis is represented by No of Study and playing time is represented by red and cyan color respectively. 

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

9a245f21ae984f1daa5ffb1a11f386de.png

Example #2 : Using Stackplot 

Python3


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

Output: 
Below represents the output of graph if the value of baseline is set to zero

最后

以上就是无奈画笔为你收集整理的【数据可视化】Stackplot的全部内容,希望文章能够帮你解决【数据可视化】Stackplot所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部