1

The matplotlib.pyplot tutorial has the following code:

lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)

I'm wondering if there's anyway to specify different colours for different lines in this statement.

1 Answer 1

2

You can specify the properties of each line with the same matplotlib.pyplot.setp() method as well:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1.0, 0.01)
y1 = np.sin(2*np.pi*x) # function 1
y2 = np.sin(4*np.pi*x) # function 2
lines = plt.plot(x, y1, x, y2)

l1, l2 = lines # split lines     
plt.setp(l1, linewidth=1, color='r', linestyle='-') # set function 1 linestyle
plt.setp(l2, linewidth=1, color='g', linestyle='-') # set function 2 linestyle

plt.show()

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

LiamG_G is that what did you want?
Yes, sorry. Hadn't come back round to this yet today. Thank you!

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.