对于此示例,为什么颜色在matplotlib中不起作用? [英] Why are colors not working in matplotlib for this example?
本文介绍了对于此示例,为什么颜色在matplotlib中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我的负值没有看到红色?
Why am I not seeing any red colors for the 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 am expecting negative values to be red!
根据下面的讨论,这是最新版本的熊猫0.20.2中的错误.
As per our discussion below, this is a bug in the latest version of pandas 0.20.2.
推荐答案
This is due to the bug as mentioned by @johnchase.
一种解决方法,直到解决为止:
One workaround till it gets resolved :
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))
输出
这篇关于对于此示例,为什么颜色在matplotlib中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文