Reputation: 1518
I have a cell that looks like this:
from IPython.display import Image
i = Image(filename='test.png')
i
print("test")
The output is just:
test
I don't see the image in the output. I checked to see that the file exists (anyway, if it did not exist, you get an error).
Any clues?
Upvotes: 10
Views: 36725
Reputation: 3511
After looking into the code, I can say, that under Windows, as of IPython 7.1.0, this is only supported with %matplotlib inline
, which does not work under the interactive IPython shell.
There is extra code in Jupyter. The following example works with
jupyter qtconsole
jupyter notebook
jupyter console
in principle, but only via external program, and then for the example the temporary file got deleted
def test_display():
import pyx
c = pyx.canvas.canvas()
circle = pyx.path.circle(0, 0, 2)
c.stroke(circle, [pyx.style.linewidth.Thick,pyx.color.rgb.red])
return c
display(test_display())
Upvotes: 0
Reputation: 869
I had the same problem. Matplot lib expects to show figs outside the command line, for example in the GTK or QT.
Use this: get_ipython().magic(u'matplotlib inline')
It will enable inline backend for usage with IPython notebook.
Upvotes: 2
Reputation: 38598
creating the image with
i = Image(filename='test.png')
only creates the object to display. Objects are displayed by one of two actions:
a direct call to IPython.display.display(obj)
, e.g.
from IPython.display import display
display(i)
the displayhook
, which automatically displays the result of the cell, which is to say putting i
on the last line of the cell. The lone i
in your example doesn't display because it is not the last thing in the cell. So while this doesn't display the image:
i = Image(filename='test.png')
i
print("test")
This would:
i = Image(filename='test.png')
print("test")
i
Upvotes: 15