Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions examples/pylab_examples/masked_demo.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/usr/bin/env python
'''
Plot lines with points masked out.

This would typically be used with gappy data, to
break the line at the data gaps.
'''

from pylab import *
import matplotlib.pyplot as plt
import numpy as np

x = ma.arange(0, 2*pi, 0.02)
y = ma.sin(x)
y1 = sin(2*x)
y2 = sin(3*x)
ym1 = ma.masked_where(y1 > 0.5, y1)
ym2 = ma.masked_where(y2 < -0.5, y2)
x = np.arange(0, 2*np.pi, 0.02)
y = np.sin(x)
y1 = np.sin(2*x)
y2 = np.sin(3*x)
ym1 = np.ma.masked_where(y1 > 0.5, y1)
ym2 = np.ma.masked_where(y2 < -0.5, y2)

lines = plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo')
setp(lines[0], linewidth=4)
setp(lines[1], linewidth=2)
setp(lines[2], markersize=10)
lines = plt.plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo')
plt.setp(lines[0], linewidth=4)
plt.setp(lines[1], linewidth=2)
plt.setp(lines[2], markersize=10)

legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'),
loc='upper right')
title('Masked line demo')
show()
plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'),
loc='upper right')
plt.title('Masked line demo')
plt.show()