[英]Matplotlib style not working in pandas bar plot
根據熊貓可視化教程,我用來生成條形圖的代碼。
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藍色。
我懷疑問題出在大熊貓上。 不使用熊貓時顏色正確。
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創建了我的環境。
In [22]: pd.__version__
Out[22]: u'0.17.1'
如何讓大熊貓繪制正確的顏色?
正如ali_m在注釋中指出的那樣,這是使用matplotlib 1.5.0版時最新版本的pandas(0.17.1)中的錯誤 。
該修復程序將在下一個熊貓版本中發布。
在新版本發布之前,我已經運行
pip install git+git://github.com/pydata/pandas.git@master
在我的conda環境中獲取最新修復程序。
該錯誤現在似乎已修復。 當我在原始問題中運行代碼時,我得到朱紅色的條。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.