matplotlib图例中的对齐文本

时间:2019-06-11 15:33:33

标签: python matplotlib text-alignment

考虑情节

x = np.linspace(0,1)
plt.plot(x, x**2, label="My first line 2.2")
plt.plot(x, x**3, label="My second line 3.2")
plt.plot(x, x, label="His line 6.12")

plt.legend()
plt.show()

enter image description here

是否有一种方法可以使matplotlib图例中的文本对齐,从而使文本向左对齐(按原样),而数字向右对齐?也就是说,我希望图例看起来像这样

My first line  2.2 
My second line 3.2
His line       6.12

以下内容当然适用于等宽字体,但不适用于我想要的比例字体

plt.plot(x, x**2, label="My first line  2.2")
plt.plot(x, x**3, label="My second line 3.2")
plt.plot(x, x,    label="His line       6.12")

0 个答案:

没有答案
相关问题