答案 0 :(得分:1)
将标题放置在图例项左侧的一种方法是将标题从组成图例的垂直包装机中取出,并用图例列水平包装。
然后,它将与新创建的第一列的顶部对齐。
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for i in range(4):
ax.plot(np.arange(4)+i, label="label {}".format(i+1))
legend = ax.legend(title="Looong Title", ncol=2, loc="upper left")
def legend_title_left(leg):
c = leg.get_children()[0]
title = c.get_children()[0]
hpack = c.get_children()[1]
c._children = [hpack]
hpack._children = [title] + hpack.get_children()
legend_title_left(legend)
plt.show()
答案 1 :(得分:0)