Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 61d2fb7

Browse files
Chang Shewesm
Chang She
authored andcommittedJun 19, 2012
BUG: mask NaNs in non-ts plots
1 parent 5282a29 commit 61d2fb7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎pandas/tools/plotting.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ def _make_plot(self):
615615
if self.style:
616616
style = self.style
617617

618+
mask = com.isnull(y)
619+
if mask.any():
620+
y = np.ma.array(y)
621+
y = np.ma.masked_where(mask, y)
618622
plotf(ax, x, y, style, label=label, **self.kwds)
619623
ax.grid(self.grid)
620624
idx = getattr(self.data, 'index', None)

‎pandas/tseries/tests/test_plotting.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,34 @@ def test_gaps(self):
207207
mask = data.mask
208208
self.assert_(mask[5:25, 1].all())
209209

210+
# irregular
211+
plt.close('all')
212+
ts = tm.makeTimeSeries()
213+
ts = ts[[0, 1, 2, 5, 7, 9, 12, 15, 20]]
214+
ts[2:5] = np.nan
215+
ax = ts.plot()
216+
lines = ax.get_lines()
217+
self.assert_(len(lines) == 1)
218+
l = lines[0]
219+
data = l.get_xydata()
220+
self.assert_(isinstance(data, np.ma.core.MaskedArray))
221+
mask = data.mask
222+
self.assert_(mask[2:5, 1].all())
223+
224+
# non-ts
225+
plt.close('all')
226+
idx = [0, 1, 2, 5, 7, 9, 12, 15, 20]
227+
ser = Series(np.random.randn(len(idx)), idx)
228+
ser[2:5] = np.nan
229+
ax = ser.plot()
230+
lines = ax.get_lines()
231+
self.assert_(len(lines) == 1)
232+
l = lines[0]
233+
data = l.get_xydata()
234+
self.assert_(isinstance(data, np.ma.core.MaskedArray))
235+
mask = data.mask
236+
self.assert_(mask[2:5, 1].all())
237+
210238
@slow
211239
def test_secondary_y(self):
212240
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)
Please sign in to comment.