matplotlib 设置图例legend位置
loc参数
| Location String | Location Code |
| 'best' | 0 |
| 'upper right' | 1 |
| 'upper left' | 2 |
| 'lower left' | 3 |
| 'lower right' | 4 |
| 'right' | 5 |
| 'center left' | 6 |
| 'center right' | 7 |
| 'lower center' | 8 |
| 'upper center' | 9 |
| 'center' | 10 |
示例
from matplotlib import pyplot as plt plt.plot([0, 1, 9], [3, 8, 2], label='asd') plt.legend(loc=0) plt.show()
bbox_to_anchor参数
参数值为一个元组,第一个数字代表横轴偏移量,第二个数字代表纵轴偏移量
示例
from matplotlib import pyplot as plt plt.plot([0, 1, 9], [3, 8, 2], label='asd') plt.legend(bbox_to_anchor=(0.2, 1.1)) plt.show()

浙公网安备 33010602011771号