简体   繁体   English

如何在 python 中使用 matplotlib 对时间序列数据进行 plot 堆积条形图?

[英]How to plot a stacked bar chart on time series data using matplotlib in python?

I am trying to plot a stacked bar chart on my data.我正在尝试 plot 我的数据上的堆积条形图。 I have data like this:我有这样的数据:

received_date :[ 2016-07-28,2016-10-10,2016-11-11,2016-12-09,2017-01-10]
null_count : [820145,1004174,1165932,1167409,1214356]   
total_count: [6356161,6344421,6428218,6405691,6409394]

Dates are from 2016-2022.日期为 2016-2022 年。

something like this像这样的东西

X axis: Dates grouped by years/months X 轴:按年/月分组的日期

Y axis: Count representing both null_count and total_count.. Y 轴:表示 null_count 和 total_count 的计数。

Been trying for 2 days now...Any help would be very much appreciated.现在已经尝试了 2 天......任何帮助将不胜感激。

import matplotlib.pyplot as plt 
import numpy as np

received_date = [ '2016-07-28','2016-10-10','2016-11-11','2016-12-09','2017-01-10']
null_count =  np.array([820145,1004174,1165932,1167409,1214356])   
total_count = np.array([6356161,6344421,6428218,6405691,6409394])

plt.bar(received_date,null_count,color='b')
plt.bar(received_date,total_count,bottom=null_count,color='r')

plt.show()

Hope this helps:)希望这可以帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM