如何将传奇与大 pandas 放到情节之外 [英] How to put legend outside the plot with pandas
本文介绍了如何将传奇与大 pandas 放到情节之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将图例放置在情节之外?
How is it possible to put legend outside the plot?
import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}
d = pd.DataFrame(a).T
#print d
f = plt.figure()
plt.title('Title here!', color='black')
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
d.plot(kind='bar', ax=f.gca())
plt.show()
推荐答案
我认为您需要在添加调用legend
之前先调用plot
.
I think you need to call plot
before you add the calling legend
.
import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}
d = pd.DataFrame(a).T
#print d
f = plt.figure()
plt.title('Title here!', color='black')
d.plot(kind='bar', ax=f.gca())
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.show()
-----熊猫解决方案 如果您使用的是熊猫Dataframe.plot
----- Panda solution If you are using pandas Dataframe.plot
dataframe_var.plot.bar().legend(loc='center left',bbox_to_anchor=(1.0, 0.5));
这篇关于如何将传奇与大 pandas 放到情节之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文