对于此示例,为什么颜色在matplotlib中不起作用?

编程入门 行业动态 更新时间:2024-10-28 16:21:28
本文介绍了对于此示例,为什么颜色在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.

推荐答案

这是由于 bug ,如@johnchase所述.

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中不起作用?

本文发布于:2023-11-15 07:03:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1592204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:于此   示例   中不   颜色   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!