# python堆积图的画法_Matplotlib: 堆积柱状图的画法

import matplotlib.pyplot as plt

y1 = np.array([1,2,3,4])

y2 = np.array([1,1,1,1])

x = np.array([2009,2010,2011,2012])

plt.figure(figsize=(4,4))

plt.bar(x, y1, label='a')

plt.bar(x, y2, bottom=y1, label='b')

leg = plt.legend(loc='lower center',frameon=False,bbox_to_anchor=(0.5, -0.18),ncol=2)

plt.show()

y3的bottom为y1+y2

y4的bottom为y1+y2+y3import numpy as np

import matplotlib.pyplot as plt

y1 = np.array([1,2,3,4])

y2 = np.array([1,1,1,1])

y3 = np.array([2,1,2,3])

y = [y1, y2, y3]

y_c = np.cumsum(y, 0)

labels = ['a', 'b', 'c']

x = np.array([2009,2010,2011,2012])

plt.figure(figsize=(4,4.5))

for i in range(3):

if i == 0:

plt.bar(x, y[i], label=labels[i])

else:

plt.bar(x, y[i], bottom=y_c[i-1], label=labels[i])

leg = plt.legend(loc='lower center',frameon=False,bbox_to_anchor=(0.5, -0.18),ncol=3)

plt.show()

https://www.jianshu.com/p/4af70ed49484

09-18

08-23 2418
06-03
03-02 229
08-28 6419
12-20 1万+
04-25 9299
07-12 2万+
10-16 6417
04-09 1万+