From: Benjamin Root <ben.root@ou...>  20110930 14:36:26

2011/9/30 Александров Петр <petr_aleksandrov@...> > How to make a plot of a discontinuous 1d function without line at a > function jump. An example is shown on a picture. This was plotted by: > import numpy > from matplotlib import pyplot > x = numpy.linspace(1.0, 1.0, 100) > y = numpy.sign(x) * numpy.cos(x) > axes = pyplot.gca() > axes.set_ylim(1.1, 1.1) > pyplot.plot(x, y) > > If you happen to know where the discontinuity is, then you could do two separate plot commands. Automatically, it is harder. Maybe something like this would help: threshold = 1000.0 # Use gradient instead of diff because it returns an array of the same shape dydx = numpy.gradient(y) / numpy.gradient(x) idx = (numpy.abs(dydx) < threshold) axes.plot(x[idx], y[idx]) Although, that gets rid of valid data points. Another trick would be to rebuild the x and y arrays, but with NaNs placed between datapoints that would form the discontinuity. matplotlib automatically treats NaNs as a indicator to break a line. Ben Root 