I have a DF with grouped data such as:
fieldsX = ['Year_start','Week_start']
f = { 'Integrado':['count'], 'Duration_hours':['min','mean','max'] }
a = a.groupby(fieldsX).agg(f)
This is a snippet of the DF...
Duration_hours Integrado
min mean max count
Year_start Week_start
2017 1 428.9 428.900000 428.9 1
2 0.5 19.566667 119.8 9
3 0.9 14.112500 96.4 16
4 1.5 2.850000 4.2 2
5 1.8 3.540000 5.5 5
6 0.7 2.242857 6.2 7
7 0.4 113.075000 696.2 8
8 1.0 163.375000 1158.5 8
I'm trying to plot this, using the secondary_y
[a] axis for the Integrado
field.
ax = a.plot(kind='bar', legend=True, fontsize=8, figsize=(15, 10), secondary_y=['Integrado'])
But I cannot achieve it. All the data is using the y axis on the left.
As per [a] and [b] I should declare a list including which columns should be using the secondary axis, but it's now working.
UPDATE: following this, I've managed to use the secondary axis. Have a look.
The trick is to create a fig object and a second ax2
axis object.
fig = plt.figure()
ax = fig.add_subplot(111)
ax2 = ax.twinx()
a.Integrado.plot(kind='bar',ax=ax)
a.Duration_hours.plot(kind='line',ax=ax2)
The problem now is that on the x-axis
, the data (year,week)
is gone, in comparison to the previous plot.
1) Ideas on how to have the x-axis information?
2) Why is the parameter secondary_y
not working at all?
Thanks!
[a] - https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html
[b] - http://pandas.pydata.org/pandas-docs/version/0.21/visualization.html