Search code examples
pythonmatplotliblinelegend

MatPlotLib create labels in the legend from the df


I have created multipleline plot that shows data about different plants. Right now the legend is based on index of numbers that was creates as defult. I would like the labels to be based on a column that contains the plant names (that called ('plants')

I have tried to this this like that:

new_db.iloc[:,2:].T.plot(figsize=(17,10),label=[new_db['plant']]);

But I have still gotten the numbers as the labels:

enter image description here

My goal is to have the legend with the names of the plants

Edit: This is how the table looks like: enter image description here


Solution

  • I think that what you need is simply to do -

    plt.legend(new_db['plant'])
    

    It should work with your legend problem, however if it doesn`t. Please add more info and code on what you have tried and I will edit this answer.