要实现按年代划分的堆叠柱状图,可以使用一些常见的数据可视化库,如Matplotlib和Seaborn。下面是一个使用Matplotlib库和Python语言的示例代码:
import matplotlib.pyplot as plt
# 创建数据
years = [2010, 2011, 2012, 2013, 2014, 2015, 2016]
category1 = [10, 9, 8, 7, 6, 5, 4]
category2 = [8, 7, 6, 5, 4, 3, 2]
category3 = [6, 5, 4, 3, 2, 1, 0]
# 绘制堆叠柱状图
plt.bar(years, category1, label='Category 1')
plt.bar(years, category2, bottom=category1, label='Category 2')
plt.bar(years, category3, bottom=[i+j for i,j in zip(category1, category2)], label='Category 3')
# 添加图例、标签和标题
plt.legend()
plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Stacked Bar Chart by Year')
# 显示图形
plt.show()
这段代码将创建一个堆叠柱状图,其中每个年代都有三个类别的数据,每个类别的柱子堆叠在一起。你可以根据自己的数据和需求修改代码中的年份和类别数据。