【发布时间】:2013-10-30 02:35:46
【问题描述】:
我尝试使用ggplot for python 我有以下数据:
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]]
我想用 ggplot 表示它:
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_data 列表,以便可以将它与ggplot 一起使用,我希望第一列在时间x 轴上表示,第二列在功率y 轴上?
如果我尝试使用 meat 示例,它不会显示任何内容,只会显示
>>> print (ggplot(aes(x='date', y='beef'), data=meat) + \
... geom_line())
<ggplot: (20096197)>
>>>
我应该怎么做才能进一步显示图形?
【问题讨论】:
标签: python python-2.7 pandas python-ggplot