1 回答
TA贡献1818条经验 获得超7个赞
这是你想要的吗?
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('xx-small')
fig = plt.figure(figsize=(7.2, 7.2/2))
ax = fig.add_axes([0.1, 0.1, 0.3, 0.8])
p1, = ax.plot([1, 2, 3], label='Opt. Flat. No Gamma. - cross - standard situation - Criterion taken into account a=200')
p2, = ax.plot([3, 2, 1], label='Pess. Flat. No Gamma. - Criterion taken into account a=200')
legend = ax.legend(handles=[p1, p2], bbox_to_anchor=(1.05, 1), loc='upper left', prop=fontP)
#renderer = fig.canvas.get_renderer()
#shift = max([t.get_window_extent(renderer).width for t in legend.get_texts()])
#for t in legend.get_texts():
# t.set_ha('right') # ha is alias for horizontalalignment
# t.set_position((shift,0))
添加回答
举报