How do I assign multiple labels at once in matplotlib?

前端 未结 9 1503
半阙折子戏
半阙折子戏 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:06

    In case of numpy matrix plot assign multiple legends at once for each column

    I would like to answer this question based on plotting a matrix that has two columns.

    Say you have a 2 column matrix Ret

    then one may use this code to assign multiple labels at once

    import pandas as pd, numpy as np, matplotlib.pyplot as plt
    pd.DataFrame(Ret).plot()
    
    plt.xlabel('time')
    plt.ylabel('Return')
    plt.legend(['Bond Ret','Equity Ret'], loc=0)
    plt.show()
    

    I hope this helps

提交回复
热议问题