我是靠谱客的博主 酷酷柚子,最近开发中收集的这篇文章主要介绍【Python】画个堆积柱状图(三类数据的),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

# 堆积图
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams["font.sans-serif"] = ["SimHei"]

x = [1, 2, 3, 4, 5, 6 ,7,8,9,10,11,12,13,14]
y = [0.4101,0.4535,0.4881,0.4604,0.4539,0.4054,0.4359,0.4531,0.4471,0.4630,0.4542,0.4235,0.4301,0.4523]
y1 = [0.2874,0.2647,0.2335,0.2579,0.2553,0.2837,0.2336,0.2050,0.2243,0.2233,0.2194,0.2341,0.2266,0.1904]
y2 = [0.3023,0.2817,0.2782,0.2816,0.2907,0.3108,0.3304,0.3417,0.3284,0.3135,0.3262,0.3422,0.3432,0.3571]

plt.bar(x, y, align="center", color="orange", tick_label=["李世民", "李治", "武曌", "李隆基", "李亨","李豫","李适","李纯","李昂","李炎","李忱","李漼","李儇","李柷"], label="消极")
plt.bar(x, y1, align="center", bottom=y, color="#91B493", label="积极")
for i in range(0, len(y)):
    y1[i] = y1[i] + y[i]
plt.bar(x, y2, align="center", bottom=y1, color="#F6C555", label="中立")
plt.xlabel("xxx")
plt.ylabel("xx")
plt.ylim(0,1)
plt.legend()
plt.show()

注意地方就是在设置第三类数据的底部,应该是第一类加第二类作底部:

plt.bar(x, y2, align="center", bottom=y1, color="#F6C555", label="中立")

 

结果:

最后

以上就是酷酷柚子为你收集整理的【Python】画个堆积柱状图(三类数据的)的全部内容,希望文章能够帮你解决【Python】画个堆积柱状图(三类数据的)所遇到的程序开发问题。

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

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

评论列表共有 0 条评论

立即
投稿
返回
顶部