2

Hi I have a numpy array

a = np.random.uniform(0,1, size = (10,3))

I want to plot each of the columns with its own label

plt.plot(a, label = ['label1', 'label2', 'label3'])
plt.legend()

How can I do that? The above is my tentative, but didn't work.

2 Answers 2

3

A slightly shorter approach (because the handles are already present in the legend):

import numpy as np
import matplotlib.pyplot as plt

a = np.random.uniform(0,1, size = (10,3))

plt.plot(a)
plt.legend(['label1', 'label2', 'label3'])

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

0

I think I found it here

l1,l2, l3 = plt.plot(a)
plt.legend((l1,l2, l3), ('label1', 'label2', 'label3'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.