Ask Your Question
0

How can I show any image in sage notebook via html?

asked 2013-10-20 07:25:10 +0100

AndreWin gravatar image

Hello! I type in sage notebook 5.12 (linux mint 15 cinnamon):

html("<img src='1.png'></img>")

If 1.png is placed in DATA path, my code works fine.
When 1.png is placed in any other path, I can't do anything my code work.
Is it possible to show any image in sage notebook via html code?
I need html to create html output with images from my functions.
Please help me. Thanks a lot!)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-10-21 03:22:17 +0100

AndreWin gravatar image

It seems I found the answer!)
In Firefox browser I pressed ctrl+U to get html code of sage worksheet web page. Then I pressed ctrl+F (the search) and typed "img" (without quotes). I found that image (logo of sage at left top corner of sage worksheet) is sagenb.png. After that in terminal:

locate sagenb.png

The result for me from locate function is:
/home/andrei/sage-5.10/devel/sagenb-main/sagenb/data/sage/images/sagenb.png
So this image folder is that place where I can store my image files.

edit flag offensive delete link more
0

answered 2013-10-20 09:41:26 +0100

vdelecroix gravatar image

Hello,

If you create your image from a function, then you can sage them in DATA.

P = line([(0,0),(1,1)], color='red')
P.save(DATA + 'my_picture.png')

and then use the code you mentioned

html("<img src='my_picture.png'></img>")

Otherwise, if you want to use pictures from another repository, I am not sure that it is possible.

edit flag offensive delete link more

Comments

Thank you very much, but I know how to use DATA. The help information and pictures aren't in DATA so I should use them from other places.

AndreWin gravatar imageAndreWin ( 2013-10-20 09:57:17 +0100 )edit
1

In the notebook, the variable DATA is a Python string that points to the data directory of your worksheet. It is simply some directory on your computer. The simplest would be that you copy your files to that directory (either by a direct copy or using the menu "data" in the worksheet). The reason why this directory exists is that you will be able to save and share your worksheet with the pictures.

vdelecroix gravatar imagevdelecroix ( 2013-10-20 10:15:49 +0100 )edit

I have another task so I tell about it in more detail. I create my own technical library of functions for sage. Any user copy my files in required places to have my functions working. I should have only one place with my images for docstring of my function. My library isn't for online version of sage. Also I don't need to share these images for docstring - other user should copy and install my files. So it's not good to have images for my docstring in DATA folder (there are new DATA folder for each new worksheet and after user delete help function in code, images for docstring are still in DATA).

AndreWin gravatar imageAndreWin ( 2013-10-21 03:15:57 +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: 2013-10-20 07:25:10 +0100

Seen: 1,029 times

Last updated: Oct 21 '13