Problem statement: Create stack plot in python (using matplotlib.pyplot).
问题陈述:在python中创建堆栈图(使用matplotlib.pyplot)。
Program:
程序:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18import matplotlib.pyplot as plt days=[1,2,3,4,5] sleeping = [7,8,6,11,7] eating = [2,3,4,3,2] working = [7,8,7,2,2] playing = [8,5,7,8,13] plt.plot([],[],color ='m', label = 'Sleeping', linewidth = 5) plt.plot([],[],color ='c', label = 'Eating', linewidth = 5) plt.plot([],[],color ='r', label = 'Working', linewidth = 5) plt.plot([],[],color ='y', label = 'Playing', linewidth = 5) plt.stackplot(days, sleeping, eating, working, playing, colors = ['m','c','r','y']) plt.xlabel('Days') plt.ylabel('Hours') plt.title('Stack Plot1') plt.xticks(days, ('Mon', 'Tue', 'Wed', 'Thur', 'Fri')) plt.legend() plt.show()
Output
输出量
Explanation:
说明:
Stackplot function is used to draw stackplot in python. The xlable, ylabel title gives the labels and title to the plot. Different colors can be given to the different levels of the stack plot.
Stackplot函数用于在python中绘制stackplot。 xlable和ylabel标题提供了图的标签和标题。 可以为堆栈图的不同级别赋予不同的颜色。
翻译自: https://www.includehelp.com/python/stack-plot-using-matplotlib-pyplot.aspx
最后
以上就是善良故事最近收集整理的关于Python | 使用matplotlib.pyplot创建堆栈图的全部内容,更多相关Python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复