擅长:python、mysql、java
<p>聚合示例:</p>
<p>如果熊猫的颜色美学像ggplot,我想做如下事情:</p>
<pre><code>aggregated = df.groupby(['model', 'training_examples']).aggregate(np.mean)
aggregated.plot(x='training_examples', y='accuracy', label='model')
</code></pre>
<p>(列:模型为字符串,训练示例为整数,精度为十进制)</p>
<p>但那只会造成混乱。</p>
<p>多亏了乔里斯的回答,我最终得到了:</p>
<pre><code>for index, group in df.groupby(['model']):
group_agg = group.groupby(['training_examples']).aggregate(np.mean)
group_agg.plot(y='accuracy', label=index)
</code></pre>
<p>我发现<code>title=</code>只是在每个循环迭代中替换了绘图的单个标题,但是<code>label=</code>做了您所期望的--<em>当然是在运行<code>plt.legend()</code>之后。</p>