use*_*828 33 python matplotlib pandas
怎么可能把传说放在情节之外?
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()
Run Code Online (Sandbox Code Playgroud)
Phi*_*hil 58
我想你需要plot在添加呼叫之前打电话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()
Run Code Online (Sandbox Code Playgroud)
根据 OP 的问题,我可以使用以下代码段将图例放在图表之外:
import pandas as pd
import matplotlib.pyplot as plt
a = {'Test1': {1: 21867186, 4: 20145576, 10: 18018537},
'Test2': {1: 23256313, 4: 21668216, 10: 19795367}}
df = pd.DataFrame(a).T
ax = df.plot.bar()
ax.set_title("Title here!",color='black')
ax.legend(bbox_to_anchor=(1.0, 1.0))
ax.plot()
Run Code Online (Sandbox Code Playgroud)
然后,您可以修改锚点值以根据需要调整其位置。锚点将是该图表的左下角。
| 归档时间: |
|
| 查看次数: |
55806 次 |
| 最近记录: |