Last active
February 9, 2019 20:41
-
-
Save tomascsantos/7e3558213bbedb3932e20fc093ca4a72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def displayImage(imgArray, original): | |
#import original | |
original = plt.imread(f).astype(np.uint8) | |
#reshape modified to match original | |
imgArray = np.reshape(imgArray, original.shape) | |
#make sure the type is correct | |
imgArray = imgArray.astype(np.uint8) | |
newImg = Image.fromarray(imgArray) | |
#prepare figure: | |
fig = plt.figure(figsize=(12,16)) | |
plt.imshow(newImg, plt.cm.gray) | |
plt.show() | |
--------------------------------------------------------------------------- | |
AttributeError Traceback (most recent call last) | |
~/anaconda3/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) | |
~/anaconda3/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)) | |
~/anaconda3/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': | |
~/anaconda3/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) | |
~/anaconda3/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 | |
~/anaconda3/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: | |
~/anaconda3/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: | |
~/anaconda3/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') | |
~/anaconda3/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 | |
~/anaconda3/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: | |
~/anaconda3/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') | |
~/anaconda3/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 | |
~/anaconda3/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: | |
~/anaconda3/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) | |
~/anaconda3/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): | |
~/anaconda3/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) | |
410 | |
411 mask = np.empty(A.shape, dtype=np.float32) | |
--> 412 if A.mask.shape == A.shape: | |
413 # this is the case of a nontrivial mask | |
414 mask[:] = np.where(A.mask, np.float32(np.nan), | |
AttributeError: 'numpy.ndarray' object has no attribute 'mask' | |
<matplotlib.figure.Figure at 0x7f19b3601c18> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment