gpt4 book ai didi

python - 在 matplotlib 中拆分图例

转载 作者:行者123 更新时间:2023-11-28 16:48:20 26 4
gpt4 key购买 nike

是否可以将一个大图例拆分成多个(通常是 2 个)小图例。

from pylab import *

t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, linewidth=1.0, label="Graph1")
grid(True)
s = sin(4*pi*t)
plot(t, s, color='r',linewidth=1.0, label="Graph2")

legend(loc='lower left')
show()

我想将图例分成两部分并将它们放在空白处。

最佳答案

我从http://matplotlib.sourceforge.net/users/plotting/examples/simple_legend02.py得到了答案

from pylab import *

t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
p1, = plot(t, s, linewidth=1.0, label="Graph1")
grid(True)
s = sin(4*pi*t)
p2, = plot(t, s, color='r',linewidth=1.0, label="Graph2")

l1 = legend([p1], ["Graph1"], loc=1)
l2 = legend([p2], ["Graph2"], loc=4)
gca().add_artist(l1)

show()

这里,唯一的缺点是我必须给标签名两次。

enter image description here

关于python - 在 matplotlib 中拆分图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11408459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com