我想将图例标题格式化为等宽。我有:
width = 8
print_slope = "{0:.5F}".format(slope)
print_intercept = "{0:.5F}".format(intercept)
print_r_squared = "{0:.5F}".format(r_value**2)
ax.legend(prop={'family': 'monospace'},title='Slope: '+str(print_slope.rjust(width))+'\nIntercept: '+str(print_intercept.rjust(width))+'\nR-squared: '+str(print_r_squared.rjust(width)))
然而,我得到的输出给了我可变宽度的图例标题,系列是等宽的:
如何将标题也改为等宽?感谢。
答案 0 :(得分:2)
我认为您应该通过单独的电话设置图例的标题。
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [3, 2, 1], 'k-', label='data')
leg = ax.legend(prop={'size': 20})
leg.set_title('Legend Title', prop={'size': 14, 'weight': 'heavy'})