Re: [Matplotlib-users] Bar plot choose colours

2015年10月29日 02:44:27 -0700

Thanks for taking the time to respond
I am receiving the error:
AttributeError: 'Series' object has no attribute 'iterrow'
I will look into this further.
thank you
On Thu, Oct 29, 2015 at 2:31 PM, Joshua Klein <mobiuskl...@gmail.com> wrote:
> 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

Reply via email to