Python:如何将ggplot与简单的2列数组一起使用?

Python:如何将ggplot与简单的2列数组一起使用?,python,python-2.7,pandas,python-ggplot,Python,Python 2.7,Pandas,Python Ggplot,我尝试使用以下数据: power_data = [[ 4.13877565e+04, 2.34652000e-01], [ 4.13877565e+04, 2.36125000e-01], [ 4.13877565e+04, 2.34772000e-01], ... [ 4.13882896e+04, 2.29006000e-01], [ 4.13882896e+04, 2.29019000e-01], [ 4.13882896e+04, 2.28404000

我尝试使用以下数据:

power_data = [[  4.13877565e+04,   2.34652000e-01],
[  4.13877565e+04,   2.36125000e-01],
[  4.13877565e+04,   2.34772000e-01],
...
[  4.13882896e+04,   2.29006000e-01],
[  4.13882896e+04,   2.29019000e-01],
[  4.13882896e+04,   2.28404000e-01]]
我想用这个来代表它:

print ggplot(aes(x='TIME', y='Watts'), data=power_data) + \
    geom_point(color='lightblue') + \
    geom_line(alpha=0.25) + \
    stat_smooth(span=.05, color='black') + \
    ggtitle("Power comnsuption over 13 hours") + \
    xlab("Time") + \
    ylab("Watts")
但是得到错误:

  File "C:\PYTHON27\lib\site-packages\ggplot\ggplot.py", line 59, in __init__
    for ae, name in self.aesthetics.iteritems():
AttributeError: 'list' object has no attribute 'iteritems'
>>>
我不知道这行
aes(x='TIME',y='Watts')
应该做什么

如何格式化
power\u数据
列表,以便与ggplot一起使用,我希望在时间
x
轴上报告第一列,在power
y
轴上报告第二列

如果我尝试使用
meat
示例,它不会显示任何内容,它只会显示

>>> print (ggplot(aes(x='date', y='beef'), data=meat) + \
...     geom_line())
<ggplot: (20096197)>
>>>
打印(ggplot(aes(x='date',y='beef'),数据=肉)+\ …几何线() >>>
如何进一步显示图形?

我错过了3个重要步骤:

1)首先,数据的格式如下:

[{'TIME': 41387.756495162001, 'Watts': 0.234652},
 {'TIME': 41387.756500821, 'Watts': 0.236125},
 {'TIME': 41387.756506480997, 'Watts': 0.23477200000000001},
 {'TIME': 41387.756512141001, 'Watts': 0.23453099999999999},
...
 {'TIME': 41387.756574386003, 'Watts': 0.23558699999999999},
 {'TIME': 41387.756580046, 'Watts': 0.23508899999999999},
 {'TIME': 41387.756585706004, 'Watts': 0.235041},
 {'TIME': 41387.756591365003, 'Watts': 0.23541200000000001},
 {'TIME': 41387.756597013002, 'Watts': 0.23461699999999999},
 {'TIME': 41387.756602672998, 'Watts': 0.23483899999999999}]
2)然后数据需要用
DataFrame
装饰

powd = DataFrame(data2)
3)没有
plt.show(1)
绘图将不显示

以下是解决上述问题的代码:

从导入数据帧
数据2=[]
对于范围内的i(0,len(幂_数据)):
data2.append({'TIME':power_数据[i][0],'Watts':power_数据[i][1]})
powd=数据帧(数据2)
打印功率
#可以使用此行更改上述内容:
#powd=数据帧(功率数据,列=['TIME','Watts'])
#请参见评论中的sugestion
打印ggplot(aes(x='TIME',y='Watts'),数据=功率+\
几何点(颜色=‘浅蓝色’)+\
几何线(α=0.25)+\
stat_平滑(span=.05,color='black')+\
ggtitle(“超过13小时的功耗”)+\
xlab(“时间”)+\
伊拉布(“瓦特”)
一次通过,不使用中提供的:


我们还可以使用ggplot库qplot中的另一个函数来绘制图形。假设上述数据集电源数据作为输入。我们可以将其绘制为:

从ggplot导入qplot

qplot(电源数据[:,0],电源数据[:,1],type='l')

仅供参考,您无需更改数据格式。您可以使用原始格式创建所需的数据帧,格式为
powd=dataframe(power\u data,columns=['TIME','Watts'])
powd = DataFrame(power_data, columns=['TIME', 'Watts'])
print ggplot(aes(x='TIME', y='Watts'), data=powd) + \
        geom_point(color='lightblue') + \
        geom_line(alpha=0.25) + \
        stat_smooth(span=.05, color='black') + \
        ggtitle("Power comnsuption over 13 hours") + \
        xlab("Time") + \
        ylab("Watts")