Matplotlib样式在 pandas 条形图中不起作用 [英] Matplotlib style not working in pandas bar plot

查看:109
本文介绍了Matplotlib样式在 pandas 条形图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用于根据 pandas可视化生成条形图的代码教程.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('ggplot')

np.random.seed(123456)
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()

plt.figure()
df.ix[5].plot(kind='bar'); plt.axhline(0, color='k')
plt.show()

我得到:

我期望获得教程中的条形颜色(朱红色),而条形是默认的matplotlib蓝色.

I was expecting to get the bar colours as in the tutorial (vermilion), instead the bars are the default matplotlib blue colour.

我怀疑问题出在大熊猫上.不使用熊猫时颜色正确.

I suspect the problem is in pandas. Colours are correct when pandas is not used.

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('ggplot')

fig, ax = plt.subplots()
x = np.arange(5)
y1, y2 = np.random.randint(1, 25, size=(2, 5))
width = 0.25
ax.bar(x, y1, width)
ax.bar(x + width, y2, width)
ax.set_xticks(x + width)
ax.set_xticklabels(['a', 'b', 'c', 'd', 'e'])

plt.show()

我使用conda创建了环境.

I created my environment using conda.

In [22]: pd.__version__
Out[22]: u'0.17.1'

如何让大熊猫绘制正确的颜色?

How can I get pandas plot the right colours?

推荐答案

该错误现在已修复.当我在原始问题中运行代码时,会得到朱红色的条.

This bug seems to be fixed now. I get vermillion bars when I run the code in the original question.

这篇关于Matplotlib样式在 pandas 条形图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆