How do I assign multiple labels at once in matplotlib?

前端 未结 9 1502
半阙折子戏
半阙折子戏 2020-12-02 16:41

I have the following dataset:

x = [0, 1, 2, 3, 4]
y = [ [0, 1, 2, 3, 4],
      [5, 6, 7, 8, 9],
      [9, 8, 7, 6, 5] ]

Now I plot it with:

9条回答
  •  隐瞒了意图╮
    2020-12-02 17:05

    I came over the same problem and now I found a solution that is most easy! Hopefully that's not too late for you. No iterator, just assign your result to a structure...

    from numpy import *
    from matplotlib.pyplot import *
    from numpy.random import *
    
    a = rand(4,4)
    a
    >>> array([[ 0.33562406,  0.96967617,  0.69730654,  0.46542408],
       [ 0.85707323,  0.37398595,  0.82455736,  0.72127002],
       [ 0.19530943,  0.4376796 ,  0.62653007,  0.77490795],
       [ 0.97362944,  0.42720348,  0.45379479,  0.75714877]])
    
    [b,c,d,e] = plot(a)
    legend([b,c,d,e], ["b","c","d","e"], loc=1)
    show()
    

    Looks like this: enter image description here

提交回复
热议问题