Ask Your Question
0

showing an external image in sage notbook

asked 12 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 12 years ago

calc314 gravatar image

updated 12 years ago

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.

Preview: (hide)
link

Comments

Wow this is really helpful. thanks :)

ebs gravatar imageebs ( 12 years ago )

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: 12 years ago

Seen: 2,789 times

Last updated: Sep 09 '12