我正在尝试将全局图例添加到绘图中,下面的代码会执行此操作,但图例会与给定的绘图重叠(我将在下面添加绘图)。有没有办法调整传说?StackOverflow 的其他答案都集中在一个情节上,而不是使用子情节(或者我做错了什么)。
编辑:现在两个图都是重叠的,因此红色的不可见。
fig, axes = plt.subplots(n, m, figsize=(15, 8))
for var, ax in zip(vars_to_plot, axes.flat):
for solution in solutions:
ax.plot(
solution.summary_variables["Cycle number"],
solution.summary_variables[var],
)
ax.set_xlabel("Cycle number")
ax.set_ylabel(var)
ax.set_xlim([1, solution.summary_variables["Cycle number"][-1]])
fig.tight_layout()
fig.legend(['this is plot 1', 'this is plot 2'], loc='lower right')
plt.savefig("plot.png", dpi=300)