Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib not displaying image

I am trying to use matplotlib to view an image in ipython. However, I solely obtain a description of the image as opposed to seeing the actual image:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> plt.imshow(an_array)
Out[4]: <matplotlib.image.AxesImage at 0x7fb626f063d0>

This is with the backend set to Qt5Agg or TkAgg in .matplotlibrc

I have the same issues whether or not I am working in a conda virtual environment

I am running: Scientific Linux release 6.8 (Carbon), Python 2.7.13, Anaconda 4.3.0 (64-bit)

I have had similar issues on my local computer running MacOSX

I would be most grateful for any advice,

Thanks

Rob

like image 932
RobMcC Avatar asked Dec 01 '22 12:12

RobMcC


1 Answers

Add %matplotlib inline before import matplotlib.pyplot as plt to enable automatic visualization of your plots when the cell has finished executing.

Note, however, that this works just in iPython notebooks. Normally, you'd need to call plt.show() (without any arguments) to visualize the plots.

like image 82
GPhilo Avatar answered Dec 09 '22 15:12

GPhilo