The pandas plot function doesn’t take colors as it does ‘x’ or ‘y’, but it lets you pass color information just as you would with raw matplotlib code, which means you can pass it a sequence of colors which match the length of your sequence of drawn observations.
# compute color codes using a ternary expression in a list comprehension over the DataFrame colors = ['r' if row.anomaly > 0 else 'b' for i, row in meantempanomaly.iterrows()] meantempanomaly.plot(kind='bar', color=colors) On Wed, Oct 28, 2015 at 9:54 PM, questions anon <questions.a...@gmail.com> wrote: > I have calculated annual temperature anomaly and I would like to plot as a > bar plot with all values positive make red and all values negative make blue > > I am using pandas and the time series data in this example are called > 'anomaly' > > mybarplot=anomaly.plot(kind='bar') > > the data look like this: > > time > 2003-01-01 -0.370800 > 2004-01-01 -0.498199 > 2005-01-01 0.246118 > 2006-01-01 -0.313321 > 2007-01-01 0.585050 > 2008-01-01 -0.227976 > 2009-01-01 0.439337 > 2010-01-01 0.135607 > 2011-01-01 0.106105 > 2012-01-01 -0.102002 > Freq: AS-JAN, dtype: float64 > > is there some simple way of writing: > meantempanomaly.plot(kind='bar', anomaly>0:'r', anomaly<0:'b' ) > > Any feedback will be greatly appreciated > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > >
------------------------------------------------------------------------------
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users