In my notebook, I can display image in markdown from the same folder like this:
<img src="files/adaptive_filter.png" alt="Schema of adaptive filter" height="100">
If I use the code without the files/
in src
it does not work.
Now I changed the image and the ipython notebook is still showing the original one. I try to remove it from code and restart the notebook, it does not help.
What I should do? Are the images stored somewhere?
Thanks in advance.
I had the same problem of images caching in jupyter and not updating when the file is modified when using matplotlib.pyplot
. I fixed it by using IPython.display.Image
from IPython.display import Image
def saveImage(path, show=True):
plt.savefig(path, facecolor="white", bbox_inches='tight')
if show: return Image(path)
Then at the end of a code cell, something like saveImage('./someImage.png')
will save and display an image.
Similarly Image('./someImage.png')
will display an image from disk (without saving).
This seems to avoid caching issues, and the image displays in PDF exports correctly (see also Jupyter notebook matplotlib figures missing in exported pdf for the answer this is based on).
In my case, it helped reduce the size of the jupyter notebook, preventing it from crashing when rendering and updating matplotlib.pyplot
charts.
I ran into this problem as well, where I was using a class of my own to output some python plots and embed them in an IPython notebook. A hack way to solve this would be to add a random argument to the end of your image url. For example
<img src="files/adaptive_filter.png?1" alt="Schema of adaptive filter" height="100">
will not be cached in the same place as
<img src="files/adaptive_filter.png?2" alt="Schema of adaptive filter" height="100">
A programatic way to do this would be to include the picture via python, instead of markdown, for instance:
# pick a random integer with 1 in 2 billion chance of getting the same
# integer twice
import random
__counter__ = random.randint(0,2e9)
# now use IPython's rich display to display the html image with the
# new argument
from IPython.display import HTML, display
display(HTML('<img src="files/adaptive_filter.png?%d" ' +
'alt="Schema of adaptive filter" ' +
'height="100">' % __counter__))
Should update the image everytime you run the code cell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With