1.) I strongly suggest that you familiarize yourself with the python syntax:
2.) Make use of the matplotlib documentation to figure out the correct syntaxt for the plot commands you are using.
3.) In this particular case: To get you going, change your data to:
male=[2, 1, 2, 6, 6, 1] # list may increase
time=['Tue_Aug_13_04:37:40_2013', 'Mon_Jul__1_02:33:11_2013','Tue_Aug_13_04:37:40_2013', 'Thu_Jul__4_01:53:32_2013', 'Mon_Jul__1_10:05:55_2013','Mon_Jul__1_04:15:25_2013']# list may increase
female=[16, 11, 16, 12, 12, 11] # list may increase
Please examine carefully what has changed.
4.) The bar
command you try to call has not enough input arguments. With the changed data from above, try this:
ax1.bar(range(len(time)),male,width=0.5, color='red', edgecolor='black')
ax1.bar(range(len(time)),female,width=0.5,bottom=male,color='blue', edgecolor='black')
What has changed?
- you need the following inputs:
left, height, width=0.8
- you had only one of those
- due to the fact that your dates are given as strings, you need a generic counter for the
x
-axis, hence the range(len(time))
to provide as many tics as there are entries in time
.
- now, you specify the
height
according to the values in male
and female
- none of which should be strings!
- define a
width
- in your case, you want the bars to be stacked - therefore, specify the first set of values as
bottom
for the second
4.) Because time
is made up of strings, you cannot use it for the ticks. Instead, try:
ax1.set_xticklabels(time,rotation=90)
Here, you use the strings from time
as tick-labels. The rotation=90
is a nice feature so that the long strings do not overlap.
5.) If the labels are cut off by the plot window, try this:
plt.tight_layout()
plt.show()
This should get you back on track.
Good key words for a web-search inlcude:
- matplotlib stacked bar
- matplotlib tick labels rotation
- matplotlib ticks date