3

If I understand correctly, the function:

matplotlib.pyplot.plot(x, y)

plots len(x)-1 separate line segments - one going from (x[0], y[0]) to (x[1],y[1]), one going from (x[1],y[1]) to (x[2], y[2]), etc. In my application, I want to display a curve consisting of a series of line segments connecting data points in this way, but there is an extra piece of data (z) associated with the transition between each of these data points, that I want to represent by the color of the line segment. Clearly one way of doing this is the following:

for i in range(len(x)-1)):
    matplotlib.pyplot.plot(x[i:i+2],y[i:i+2], color=z[i])

but is there a way to do it that doesn't involve a separate call to matplotlib.pyplot.plot for each line segment?

1 Answer 1

1

You should be able to use matplotlib.collections.LineCollection which accepts a colors parameter (sequence of RGBA tuples).

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

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.