ims*_*msc 7 python matplotlib legend
是否有可能将一个大图例分成多个(通常是 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()
Run Code Online (Sandbox Code Playgroud)
我想将图例分成两部分并将它们放置在可用空白的位置。
我从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()
Run Code Online (Sandbox Code Playgroud)
在这里,唯一的缺点是我必须给出标签名称两次。

| 归档时间: |
|
| 查看次数: |
11066 次 |
| 最近记录: |