Q: matplotlib list not showing 0 or Nan's Hi I have a list with X and a list with Y. I want to plot them using matplotlib.plt.plot(x,y)
I have some values of y that are 0 or 'empty' how can I make it that matplot doesn't connect the 0 or empty dots? and shows the rest? Do I have to split it into different lists?
Thanks in advance!

A: If you use numpy.nan instead of 0 or empty the line gets disconnected.
See:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,20)
y = np.sin(x)
y[3] = np.nan
y[7] = np.nan
plt.plot(x,y)



A: Use np.where to set the data not to be plotted to np.nan.
from numpy import *
a=linspace(1, 50, 1000)
b=sin(a)
c=where(b>-0.7, b, nan) #In this example, we plot only the values larger than -0.7
#if you want to skip the 0, c=where(b!=0, b, nan)
plt.plot(c)


