You are reading an old version of the documentation (v1.4.3). For the latest version see

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

pylab_examples example code:

Next topic

pylab_examples example code:

This Page

pylab_examples example code: nan_test.pyΒΆ

(Source code, png, hires.png, pdf)

#!/usr/bin/env python
Example: simple line plots with NaNs inserted.
from pylab import *
import numpy as np

t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)
t[41:60] = NaN
#t[50:60] = np.inf

plot(t, s, '-', lw=2)

xlabel('time (s)')
ylabel('voltage (mV)')
title('A sine wave with a gap of NaNs between 0.4 and 0.6')

t[0] = NaN
t[-1] = NaN
plot(t, s, '-', lw=2)
title('Also with NaN in first and last point')

xlabel('time (s)')
ylabel('more nans')


Keywords: python, matplotlib, pylab, example, codex (see Search examples)