Solution: Plotting
See the solution to problems related to plotting.
We'll cover the following...
Solution 1
Given the following DataFrame df
:
Snail Cat Dog Elephant Rabbit Horse CheetahLifespan 2 12 10 50 9 25 10Speed 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 pddf=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")