Ask Your Question
0

showing an external image in sage notbook

asked 2012-09-09 21:21:54 +0100

ebs gravatar image

Is there an easy way to show an image stored in local drive (or a website) in sage notebook?

The only way I know is using matplotlib:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img=mpimg.imread('<location of image file')
plt.imshow(img)
frame = plt.gca()
frame.axes.get_xaxis().set_visible(False)
frame.axes.get_yaxis().set_visible(False)
plt.savefig("temp.png")

but, it is a roundabout way and shows the unecessary black border around the image.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-09-09 22:34:16 +0100

calc314 gravatar image

updated 2012-09-09 22:40:46 +0100

In a notebook, you can create a text cell by first positioning your mouse just above a cell and then shift-clicking. A palette will appear that includes a button on the right that will let you insert a link to an image.

You can also add some html code in the text cell by clicking on the "html" button in the palette.

If you prefer to work in a command cell, you can type:

html('<img src="http://your.website.here.com/image.png">')

to display an image.

Another option is to upload the image using the "data" menu in the notebook. You can then do something like the following.

import Image
im=Image.open(DATA+'filename.png')
im.save('example.png')

This uses some python to display the image. You can also do various filters, rotations, etc. to the image using the Image class.

edit flag offensive delete link more

Comments

Wow this is really helpful. thanks :)

ebs gravatar imageebs ( 2012-09-09 22:49:25 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-09 21:21:54 +0100

Seen: 2,744 times

Last updated: Sep 09 '12