I am trying to generate a stacked bar plot to keep track of three parameters for every hour over multiple days. The picture of a sample plot is SamplePlot. However, I have had no success with plotting this in python. The fact that I am a beginner in python, makes matters worse.
Two attempts made previously to answer this questions are: Horizontal stacked bar chart in Matplotlib and stack bar plot in matplotlib and add label to each section (and suggestions). However, I have not been able to achieve the desired results following any of the above solutions.
Can anyone please provide me with guidance as to how to generate the plot or point me in the direction?
Edit 1: The code that I have written is as follows:
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
status_day1 = [[0.2,0.3,0.5], [0.1,0.3,0.6], [0.4,0.4,0.2], [0.6,0.1,0.4]]
status_day2 = [[0.1,0.2,0.7], [0.3,0.2,0.5], [0.1,0.5,0.4], [0.2,0.5,0.3]]
day = ('Day1', 'Day2')
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111)
for x in range(0,4): #Looping through every hour
for y in range(0,3): #Looping through every parameter
if y==0:
ax.bar(1, status_day1[x][y],color='b',align='center')
elif y==1:
ax.bar(1, status_day1[x][y],color='r',align='center')
else:
ax.bar(1, status_day1[x][y],color='g',align='center')
# I am assuming that the three parameters for every hour are getting stacked on top of one another
for x in range(0,4):
for y in range(0,3):
if y==0:
ax.bar(1, status_day2[x][y],color='b',align='center')
elif y==1:
ax.bar(1, status_day2[x][y],color='r',align='center')
else:
ax.bar(1, status_day2[x][y],color='g',align='center')
ax.set_xticklabels(day)
ax.set_xlabel('Day')
ax.set_ylabel('Hours')
plt.show()