python绘制单列堆积柱形图 : python绘制单列堆积柱形图-优快云博客
一、代码
import numpy as np
import matplotlib.pyplot as plt
N = 10
menMeans = np.array([[20, 35], [15, 25], [15, 25], [15, 25], [15, 25], [15, 25], [15, 25], [15, 25], [15, 25], [15, 25]])
womenMeans = np.array([[25, 32], [22, 28], [22, 28], [22, 28], [22, 28], [22, 28], [22, 28], [22, 28], [22, 28], [22, 28]])
ind = np.arange(N) # the x locations for the groups
width = 0.4 # the width of the bars
fig, ax = plt.subplots()
# 第一列堆积柱形图
p1 = ax.bar(ind, menMeans[:,0], width)
p2 = ax.bar(ind, womenMeans[:,0], width, bottom=menMeans[:,0])
# 第二列堆积柱形图
p3 = ax.bar(ind + width, menMeans