Why in this example the colors don't work in matplotlib?
Why can't I see red colors for negative values ββhere?
df = pd.DataFrame([1, -2, 3, -4])
df['positive'] = df[[0]]>0
df[[0]].plot(kind='bar', color=df.positive.map({True: 'g', False: 'r'}))
I expect negative values ββto be red!
As per our discussion below, this is a bug in the latest pandas 0.20.2 release.
+3
source to share
1 answer
This is due to a bug as @johnchase mentioned.
Workaround to resolve it:
print(''.join(df.positive.map({True: 'g', False: 'r'}).values)) # 'grgr'
df[[0]].plot(kind='bar', color=''.join(df.positive.map({True: 'g', False: 'r'}).values))
which outputs
+2
source to share