1

I am working with matplotlib and want to plot a list of points, for example x=[1,2,3,4] and y=[1,4,6,8]. When I used plt.plot(x,y) I got a plot with lines joining the points in my graph. My problem is that I only want to be plotted some of these lines, for example the line joining (1,1) with (2,4) and the one joining (3,6) with (4,8), but ommiting the line between (2,4) and (3,6). I do not want to have two different lines, because my actual arrays are bigger and do not want to make a line for each pair of points. Is there a way I can tell matplotlib which points to join?

import matplotlib.pyplot as plt
x=[1,2,3,4]
y=[1,4,6,8]
plt.plot(x,y)

1 Answer 1

1

Insert NaNs where you want the blanks:

x=[1,2,np.nan,3,4]
y=[1,4,np.nan,6,8]
plt.plot(x,y)

enter image description here

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.