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

Viewed 28

I am trying to plot a stacked bar chart on my data. 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.

something like this

X axis : Dates grouped by years/months

Y axis : Count representing both null_count and total_count..

Been trying for 2 days now ...Any help would be very much appreciated.

1 Answers
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 :)

Related