I have a DataFrame looking like this:
amount price
age
A 40929 4066443
B 93904 9611272
C 188349 19360005
D 248438 24335536
E 205622 18888604
F 140173 12580900
G 76243 6751731
H 36859 3418329
I 29304 2758928
J 39768 3201269
K 30350 2867059
Now I'd like to plot a bar-plot with the age on the x-axis as labels. For each x-tick there should be two bars, one bar for the amount, and one for the price. I can get this working by using simply:
df.plot(kind='bar')
The problem is the scaling. The prices are so much higher that I can not really identify the amount in that graph, see:
Thus I'd like a second y-axis. I tried it using:
df.loc[:,'amount'].plot(kind='bar')
df.loc[:,'price'].plot(kind='bar',secondary_y=True)
but this just overwrites the bars and does NOT place them side-by-side.
Is there any way to do this without having to access the lower-level matplotlib (which would be possible obviously by placing the bars side by side manually)?
For now, I'm using two single plots within subplots:
df.plot(kind='bar',grid=True,subplots=True,sharex=True);
resulting in:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…