Numpy整数不会转换为rgb

时间:2014-08-18 13:25:02

标签: python numpy pandas python-ggplot

我想用Python ggplot库绘制一个非常简单的条形图identity。我在x轴上有几个分类变量,在y轴上有一个变量,并希望用y轴值填充条形图:

import pandas as pd
from ggplot import *
import numpy as np

a= pd.DataFrame(np.arange(5) ,  index = np.arange(5))
a['second_column'] = ['a', 'b', 'c', 'd', 'e']
a.columns = ['first_column', 'second_column']
ggplot(aes(x = 'second_column', y = 'first_column'), data = a) + \
geom_bar(aes(fill = 'first_column'), stat='identity')

我得到的是:

<repr(<ggplot.ggplot.ggplot at 0x7f2d70cc12d0>) failed: ValueError: Cannot convert argument type <type 'numpy.int64'> to rgba array>

如果我从美学中移除fill

a= pd.DataFrame(np.arange(5) ,  index = np.arange(5))
a['second_column'] = ['a', 'b', 'c', 'd', 'e']
a.columns = ['first_column', 'second_column']

ggplot(aes(x = 'second_column', y = 'first_column'), data = a) + \
geom_bar(stat='identity')

没有错误和良好的输出:

enter image description here

0 个答案:

没有答案