Now, we are going to look at the chart called stacked-bars.png
. This graph displays the breakdown of students who got As, Bs, Cs, Ds, and Fs in each unit.
The data you will need to recreate this chart is in the lists As
, Bs
, Cs
, Ds
, Fs
, and unit_topics
.
Save your recreated chart to a file called my_stacked_bar.png
.
Instructions
The Bs
bars will go on top of the As
bars, but at what heights will the Cs
, Ds
, and Fs
bars start?
The bottom of the bars representing the Cs
will be at the height of the As
plus the Bs
. We can do this in NumPy (a scientific computing package for Python) with the np.add
function. c_bottom
, the starting heights for the Cs
, will be:
c_bottom = np.add(As, Bs)
Underneath the definition of c_bottom
, define d_bottom
(where the Cs
end), and f_bottom
(where the Ds
end).
Create a figure of width 10
and height 8
.
Plot the As
, Bs
, Cs
, Ds
, and Fs
. Give each one the appropriate bottom
list that will stack them on top of each other.
Create a set of axes and save them to ax
.
Set the x-ticks to be range(len(unit_topics))
.
Set the x-tick labels to be the unit_topics
.
Give the plot the title you see in the final graph, and the same x-axis label and y-axis label.
Save your figure to a file called my_stacked_bar.png
.