设置图例legend显示到图形边界外

Python

box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width, box.height*0.8])
ax.legend(loc='center left', bbox_to_anchor=(0.0, 1.10), ncol=6)
# loc图例位置; bbox_to_anchor上下偏移量; ncol一行的显示个数;

Matlab

h = legend('Model1', 'Model2', 'Model3', 'Model4', 'Model5', 'Model6')
set(h, 'Orientation', 'horizon')
plt.legend()
plt.tight_layout()

 

你可能感兴趣的:(Matlab代码,Python代码)