python matplotlib 堆叠柱状图 visualization

Posted 卖山楂啦prss

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python matplotlib 堆叠柱状图 visualization相关的知识,希望对你有一定的参考价值。

from matplotlib import pyplot as plt
import numpy as np

unit_topics = ['Limits', 'Derivatives', 'Integrals', 'Diff Eq', 'Applications']
As = [6, 3, 4, 3, 5]
Bs = [8, 12, 8, 9, 10]
Cs = [13, 12, 15, 13, 14]
Ds = [2, 3, 3, 2, 1]
Fs = [1, 0, 0, 3, 0]

c_bottom = np.add(As, Bs)
d_bottom = np.add(c_bottom, Cs)
f_bottom = np.add(d_bottom, Ds)

# create our plot here
plt.figure(figsize=(10, 8))
plt.bar(range(len(As)), As, color="#D6E3B7")
plt.bar(range(len(Bs)), Bs, bottom = As, color="#95A96A")
plt.bar(range(len(c_bottom)), Cs, bottom = c_bottom, color="#869E7A")
plt.bar(range(len(d_bottom)), Ds, bottom = d_bottom, color="#45602D")
plt.bar(range(len(f_bottom)), Fs, bottom = f_bottom, color="#AB9A6F")
ax = plt.subplot()
ax.set_xticks(range(len(unit_topics)))
ax.set_xticklabels(unit_topics)
ax.set_title("Grade Distribution")
ax.set_xlabel("Math Subjects")
ax.set_ylabel("Number of Students")
plt.savefig("our_stacked_bar.png")
plt.show()

以上是关于python matplotlib 堆叠柱状图 visualization的主要内容,如果未能解决你的问题,请参考以下文章

python matplotlib 堆叠柱状图 visualization

Python使用matplotlib绘制柱状图(bar plot)实战:水平条形图垂直条形图分组条形图堆叠条形图

Python 之 Matplotlib 柱状图(竖直柱状图和水平柱状图)直方图和饼状图

matplotlib笔记二:常用图表

Python交互图表可视化Bokeh:5 柱状图| 堆叠图| 直方图

Python matplotlib绘制条形柱状图并添加数据标签