'x axes in plot bar visualization in matplotlib [duplicate]
Solution 1:[1]
You could .pivot() your DataFrame so that Year becomes the index and SubCategory the columns, then plot it.
df = pd.DataFrame({
"Year": [2000, 2000, 2001, 2001, 2002, 2002],
"Pet": ["Dog", "Cat", "Dog", "Cat", "Dog", "Cat"],
"Weight": [10, 5, 11, 6, 10, 6]})
df.pivot(index="Year", columns="Pet", values="Weight").plot.bar()
As an aside, I don't love bar plots with years along the x-axis, as I don't consider years to be a categorical variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

