如何在堆叠图中显示2013-2023年

讨论数量: 2
Jason990420
from random import randint
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei']

point = [[randint(1, 10) for i in range(12)] for j in range(11)]

for year in range(11, 0, -1):
    data = np.zeros((12,), dtype=np.int)
    for i in range(0, year):
        data += np.asarray(point[i])
    plt.bar(range(0, 12), data, label=f'{2012+year}年', width=0.5)

plt.xlabel("月份")
plt.xticks(range(0, 12), range(1, 13))
plt.ylabel("有\n降\n雨\n天\n數\n (天) ", rotation=0)
plt.legend(loc='upper right')
plt.show()
1周前 评论
135135 (楼主) 1周前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!