【问题标题】:如何使用 matplotlib 更改图例中的文本方向
【发布时间】:2022-01-14 10:30:45
【问题描述】:

我正在尝试在我的情节中添加一个图例,但它是从上到下对齐的,我怎样才能使图例中的文本水平?提前致谢。

fig, ax = plt.subplots()
sp=ax.contourf(x1line, x2line, pgrid)
plt.colorbar(sp)
ax.legend('label1')

Plot looks like this

【问题讨论】:

标签: python matplotlib legend


【解决方案1】:

ax.legend 需要一个字符串列表作为其参数。试试这个:

ax.legend(['label1'])

由于您传递了一个字符串(相对于一个列表),该字符串被视为一个可迭代对象,并且每个字符在图例中成为其自己的行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 2020-10-16
    相关资源
    最近更新 更多