identity
我想用 Python ggplot 库绘制一个非常简单的条形图。我在 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')
没有错误和很好的输出: