This is the correct behavior, mpl
tries to connect adjacent points. If you have points with a nan
on either side, there is no valid way to connect them to anything.
If you want to just ignore your nan
s when plotting, then strip them out
ind = ~np.isnan(np.asarray(data.astype(float)))
plt.plot(np.asarray(x)[ind], np.asarray(data)[ind], 'ro--')
All the asarray
are just to be sure the example will work, same with the astype
also, it is really bad practice to use variable names that shadow (both in terms of python resolution and in terms of semantic) classes (like array) or common functions.