1

I'm surprised how few are the posts relating to this problem. Anyway... here it is: I have csv data files containing X values in the first column, and several Y values columns thereafter. But for a given X value not all Y series have a corresponding value. Here is an example:

0, 16, 96, 99
10, 88, 45, 85
20, 85, 61, 10
30, 30, --, 45
40, 82, 28, 82
50, 23, 9, 61
60, 40, 77, 0
70, 26, 21, --
80, --, 58, 99
90, 1, 14, 30

when this csv data is loaded with numpy.genfromtxt, the '--' strings are taken as nan which is good. But when plotting, the plots are interrupted with blanks where there is a nan. Is there an option when a nan appears to make pyplot.plot() ignoring both the nan and the corresponding X value?

2 Answers 2

3

Not sure if matplotlib has such functionality built in, but you could home-brew it doing the following:

idx = ~numpy.isnan(Y)
pyplot.plot(X[idx], Y[idx])
Sign up to request clarification or add additional context in comments.

Comments

2

Look at this post

As proposed in my answer there, I'd recommend using np.isfinite instead of np.isnan. There might be other reasons for your plot to have discontinuities, e.f., inf

1 Comment

ok, from what I saw in the post you linked here, this one can be marked as duplicate as that one. Anyway, thanks for your solution.

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.