Solution: Plotting

See the solution to problems related to plotting.

Solution 1

Given the following DataFrame df:

Snail Cat Dog Elephant Rabbit Horse Cheetah
Lifespan 2 12 10 50 9 25 10
Speed 0.1 45 45 40 50 55 100

a) Create a bar plot.

b) Create a stacked bar plot.

Create a bar plot

Press + to interact
import pandas as pd
df=pd.DataFrame({
"": ['Lifespan','Speed'],
"Snail": [2,0.1],
"Cat" : [12, 45],
"Dog" : [10,45],
"Elephant" : [50,40],
"Rabbit" : [9,50],
"Horse" : [25,55],
"Cheetah" : [10,100]
})
plt = df.plot.bar(rot=0)
plt.get_figure().savefig("output/graph.png")
    ...