【问题标题】:Splitting the legend in matploblib在 matplotlib 中拆分图例
【发布时间】:2012-07-10 07:23:33
【问题描述】:

是否可以将一个大图例拆分为多个(通常是 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() 

我想将图例一分为二,并将它们放在可用空白处。

【问题讨论】:

    标签: python matplotlib legend


    【解决方案1】:

    我从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() 
    

    在这里,唯一的缺点是我必须给 labelname 两次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多