Reputation: 59
I have a dataframe that index is date in format(2017_01_31,....) and I have a column called 'Energy' and three other columns 'I_Base','U_Win', 'Occ'. I want to have a scatter plot of each with y set to be 'Energ' but for the condition that index is January. I tried the following code but its totally wrong.
fig, r = plt.subplots(nrows=1, ncols=3, figsize=(14,4))
for index, xcol, ax in zip(r.index.month==1,['U_Win', 'I_Base', 'Occ'], r):
df.plot(kind='scatter', x=xcol, y='Energy', ax=ax, alpha=0.5, color='r')
Thats how my dataframe is :
Index I_Base U_Win Energy Occ
2017_01_31 0.3 0.9 2.2989e+11 96
2017_01_31 0.5 0.8 2.29892e+11 40
....
2017_02_28 0.7 0.9 2.40001e+11 80
....
Upvotes: 0
Views: 98
Reputation: 3103
fig, r = plt.subplots(nrows=1, ncols=3, figsize=(14,4))
for ax, col in zip(r, ['I_Base', 'U_Win', 'Occ']):
df[df.index.month == 1].plot(kind='scatter', x=col, y='Energy', ax=ax, alpha=.5, color='r')
This will do the scatter plot where index's Datetime is Jan.
Please read this about reproducible data.
Upvotes: 1