Skip to content

Commit

Permalink
Merge pull request #1434 from wafels/temp_branch_that_fixes_normaliza…
Browse files Browse the repository at this point in the history
…tion

Fixes a regression bug on masked map data plotting
  • Loading branch information
ayshih committed Jun 10, 2015
2 parents 1320697 + 6b74c48 commit 8685a06
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
21 changes: 12 additions & 9 deletions sunpy/map/mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,10 @@ def plot(self, gamma=None, annotate=True, axes=None, **imshow_args):
kwargs = self._mpl_imshow_kwargs(axes, cmap)
kwargs.update(imshow_args)

ret = axes.imshow(self.data, **kwargs)
if self.mask is None:
ret = axes.imshow(self.data, **kwargs)
else:
ret = axes.imshow(np.ma.array(np.asarray(self.data), mask=self.mask), **kwargs)

if wcsaxes_compat.is_wcsaxes(axes):
wcsaxes_compat.default_wcs_grid(axes)
Expand All @@ -1297,17 +1300,17 @@ def _mpl_imshow_kwargs(self, axes, cmap):
Return the keyword arguments for imshow to display this map
"""
if wcsaxes_compat.is_wcsaxes(axes):
kwargs = {'cmap':cmap,
kwargs = {'cmap': cmap,
'origin': 'lower',
'norm':self.mpl_color_normalizer,
'interpolation':'nearest'}
'norm': self.mpl_color_normalizer,
'interpolation': 'nearest'}
else:
# make imshow kwargs a dict
kwargs = {'origin':'lower',
'cmap':cmap,
'norm':self.mpl_color_normalizer,
'extent':list(self.xrange.value) + list(self.yrange.value),
'interpolation':'nearest'}
kwargs = {'origin': 'lower',
'cmap': cmap,
'norm': self.mpl_color_normalizer,
'extent': list(self.xrange.value) + list(self.yrange.value),
'interpolation': 'nearest'}

return kwargs

Expand Down
10 changes: 10 additions & 0 deletions sunpy/map/tests/test_mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,13 @@ def test_rotate_invalid_order(generic_map):
@figure_test
def test_plot_aia171(aia171_test_map):
aia171_test_map.plot()


@figure_test
def test_plot_masked_aia171(aia171_test_map):
shape = aia171_test_map.data.shape
mask = np.zeros_like(aia171_test_map.data, dtype=bool)
mask[0:shape[0]/2, 0:shape[1]/2] = True
masked_map = sunpy.map.Map(np.ma.array(aia171_test_map.data, mask=mask), aia171_test_map.meta)
masked_map.plot()

3 changes: 2 additions & 1 deletion sunpy/tests/figure_hashes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"sunpy.map.tests.test_mapbase.test_plot_aia171": "62b5b9fc1a423e3cbeeea85d3b8daf1a7877099fdeda2ce9352746be1dd451fc"
"sunpy.map.tests.test_mapbase.test_plot_aia171": "62b5b9fc1a423e3cbeeea85d3b8daf1a7877099fdeda2ce9352746be1dd451fc",
"sunpy.map.tests.test_mapbase.test_plot_masked_aia171": "d70f0e5797fc864498e0bed5326afdba1e6400aa8c7aa81729f33007b4663157"
}

0 comments on commit 8685a06

Please sign in to comment.