0

I have a jupyter notebook. When I run a (python) cell that produces a plot, the plot is contained within the notebook. If someone downloads the notebook, the image is there. Whether I open the notebook in vs code or in anaconda, I see it. Even if I use it as a jupyter book and generate an .html page from the notebook, the image is there.

However, if I try to insert an image that I've created elsewhere (as a .png), it's really inserting a link to where the image is. When I build a .html page, the image is not there. If I send the .ipynb file to someone else, I have to send along the .png file for it to be visible. I want it to behave exactly like it does if I generate the image within the notebook. So I want it to really be within the notebook file, not just linked from it. All advice I've seen gives instructions for how to give the path to the image. I've seen some suggestion that this will make the image part of the .ipynb file, but in my experience it is not.

Is this possible? It seems it should be given that the system can handle images created by the code.

3
  • You are mixing concepts here and talking as if all is the same. In most cases a plot made by Python code run in a notebook is actually not an image. So right away you are on shaky ground saying, "the plot is contained within the notebook. If someone downloads the notebook, the image is there." In most cases that probably isn't an image. It is a plot object. As for the .png in the next paragraph, you have to be careful how you do this. The modern way is with attachments. Those will get embedded into the notebook file. You don't say how you are putting your .png image file into the ... Commented Oct 6, 2024 at 19:14
  • <continued> notebook but it sounds like you aren't doing it the ways that will result in embedding. It also depends on if you doing this in a markdown cell or in a code cell. You provide no details. There are ways to do this for each. See here for how you should be doing this in markdown cells. (The related Jupyter documentation for this feature is here. (My notes say this was added around 2021.) The older trick, and this works for putting images in with ... Commented Oct 6, 2024 at 19:22
  • <continued> code still, is to use from IPython.display import Image to set this up and then point at the image with Image("image.png"). When you run that code cell the image will get displayed and when you save the file if is embed in the document in base64 format. (Here is an example that is a variation on that for using a .gif.) Of course if the image is somewhere on the web you can use %%HTML cell magic at the start of a cell and point at the image with an html <img=.. tag. This won't get embedded and so only useful for things you know won't go missing. (Plus, not for nbconvert.) Commented Oct 6, 2024 at 19:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.