【问题标题】:How to center Matplotlib text legend如何使 Matplotlib 文本图例居中
【发布时间】:2022-01-17 16:14:36
【问题描述】:

我有一个带有传奇的情节。它的标题有多行像这样

由此代码创建:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot()
legend = ax.legend(title="Line 1 is short\nLine 2 is slightly longer")
plt.show()

我希望图例标题的各行居中。我该如何做到这一点?

【问题讨论】:

    标签: python matplotlib legend multiline


    【解决方案1】:

    添加这个就可以了:

    legend.get_title().set_multialignment('center')
    

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      相关资源
      最近更新 更多