【发布时间】:2021-11-03 19:23:25
【问题描述】:
我正在使用matplotlib's gallery中的代码:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.arange(10)
y = 2.5 * np.sin(x / 20 * np.pi)
yerr = np.linspace(0.05, 0.2, 10)
plt.errorbar(x, y + 3, yerr=yerr, label='both limits (default)')
plt.errorbar(x, y + 2, yerr=yerr, uplims=True, label='uplims=True')
plt.errorbar(x, y + 1, yerr=yerr, uplims=True, lolims=True,
label='uplims=True, lolims=True')
upperlimits = [True, False] * 5
lowerlimits = [False, True] * 5
plt.errorbar(x, y, yerr=yerr, uplims=upperlimits, lolims=lowerlimits,
label='subsets of uplims and lolims')
plt.legend(loc='lower right')
并且,我在 jupyter 的终端中收到以下输出:
但是,在 matplotlib 库中,图例被很好地隐藏在错误栏限制选择之下:
我该如何解决这个问题?目前我的项目的其他一些情节也有同样的问题,传说阻碍了情节,到目前为止我没有取得任何进展。
【问题讨论】:
-
另见How to put the legend out of the plot或直接更改图形大小
fig = plt.figure(figsize=(6, 5))
标签: python matplotlib plot legend