您可以屏蔽部分数组,然后matplotlib不会绘制它:
import numpy as np
import matplotlib.pylab as pl
x = np.arange(100)
y = np.cos(x/10.)
pl.figure()
pl.subplot(121)
pl.plot(x, y)
# Mask part of array
y2 = np.ma.masked_where(((x>20)&(x<30)), y)
pl.subplot(122)
pl.plot(x, y2)