Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

imshow errors when plotting completely masked array #9280

Copy link
Copy link
Closed
@mwaskom

Description

@mwaskom
Issue body actions

Bug report

Bug summary

In matplotlib 2.1, trying to imshow a masked array where all entries are masked fails. This worked in matplotlib < 2.1.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.random.randn(10, 10)
x[:] = np.nan

f, ax = plt.subplots()
ax.imshow(x)

Actual outcome

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    330                 pass
    331             else:
--> 332                 return printer(obj)
    333             # Finally look for special method names
    334             method = get_real_method(obj, self.print_method)

~/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    235 
    236     if 'png' in formats:
--> 237         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    238     if 'retina' in formats or 'png2x' in formats:
    239         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

~/anaconda2/envs/py36/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    119 
    120     bytes_io = BytesIO()
--> 121     fig.canvas.print_figure(bytes_io, **kw)
    122     data = bytes_io.getvalue()
    123     if fmt == 'svg':

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2206                     orientation=orientation,
   2207                     dryrun=True,
-> 2208                     **kwargs)
   2209                 renderer = self.figure._cachedRenderer
   2210                 bbox_inches = self.figure.get_tightbbox(renderer)

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    505 
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--> 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    428             if toolbar:
    429                 toolbar.set_cursor(cursors.WAIT)
--> 430             self.figure.draw(self.renderer)
    431         finally:
    432             if toolbar:

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
   1293 
   1294             mimage._draw_list_compositing_images(
-> 1295                 renderer, self, artists, self.suppressComposite)
   1296 
   1297             renderer.close_group('figure')

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2397             renderer.stop_rasterizing()
   2398 
-> 2399         mimage._draw_list_compositing_images(renderer, self, artists)
   2400 
   2401         renderer.close_group('axes')

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    136     if not_composite or not has_images:
    137         for a in artists:
--> 138             a.draw(renderer)
    139     else:
    140         # Composite any adjacent images together

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     53                 renderer.start_filter()
     54 
---> 55             return draw(artist, renderer, *args, **kwargs)
     56         finally:
     57             if artist.get_agg_filter() is not None:

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
    546         else:
    547             im, l, b, trans = self.make_image(
--> 548                 renderer, renderer.get_image_magnification())
    549             if im is not None:
    550                 renderer.draw_image(gc, l, b, im)

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
    772         return self._make_image(
    773             self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 774             unsampled=unsampled)
    775 
    776     def _check_unsampled_image(self, renderer):

~/anaconda2/envs/py36/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
    368                 # old versions of numpy do not work with `np.nammin`
    369                 # and `np.nanmax` as inputs
--> 370                 a_min = np.ma.min(A).astype(scaled_dtype)
    371                 a_max = np.ma.max(A).astype(scaled_dtype)
    372                 # scale the input data to [.1, .9].  The Agg

~/anaconda2/envs/py36/lib/python3.6/site-packages/numpy/ma/core.py in astype(self, newtype)
   3203                 output._mask = self._mask.astype([(n, bool) for n in names])
   3204         # Don't check _fill_value if it's None, that'll speed things up
-> 3205         if self._fill_value is not None:
   3206             output._fill_value = _check_fill_value(self._fill_value, newtype)
   3207         return output

AttributeError: 'MaskedConstant' object has no attribute '_fill_value'

Expected outcome

Matplotlib version

  • Operating system: Linux
  • Matplotlib version: 2.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.6
  • Other libraries: numpy 1.13.1

Libraries are installed from conda-forge (see failing travis build here for full details).

djhoese, 1a1a11a, mgalardini and braindevices

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.