2016-09-27 117 views
1

我使用google图表绘制下面的数据框。使用matplotlib绘制折线图的图例和标题

Group G1 G2 
Hour 
    6  19 1 
    8  1 2 

我在折线图上绘制了上面的数据框。但是我无法将图例和标题添加到折线图中。此外,我正在尝试增加折线图的尺寸,因为它看起来很小。不确定我们在matplotlib中是否有这些选项。任何帮助,将不胜感激。

import matplotlib.pyplot as plt 
plt.plot(dft2) 
plt.xlabel('Hour') 
plt.ylabel('Count') 
plt.show() 

回答

1
dfg2.plot(legend=True, figsize=(8,8)) 
plt.legend(ncol=3, bbox_to_anchor=[1.35, 1], handlelength=2, handletextpad=1, columnspacing=1, title='Legend') 

plt.title('Title here!', color='black', fontsize=17)    
plt.xlabel('Hour', fontsize=15) 
plt.ylabel('Count', fontsize=15) 
plt.show() 
+0

感谢。对不起,我搞砸了我的数据帧格式。我现在改变了数据框的格式。有了这个传说不起作用。 – user3447653

+0

如果您将plt.legend(loc ='center left',bbox_to_anchor =(1.0,0.5))更改为以下行:df.plot(legend = True) – Chichi

+0

我已将修改添加到Edit部分。除了调整图的大小之外,一切都可以工作 – user3447653