karolzak / ipyplot

IPyPlot is a small python package offering fast and efficient plotting of images inside Python Notebooks. It's using IPython with HTML for faster, richer and more interactive way of displaying big numbers of images.
MIT License
413 stars 41 forks source link

[Feature Request] Save the output of the plot #14

Closed educatorsRlearners closed 3 years ago

educatorsRlearners commented 4 years ago

My blog is written using fastpages so the output of ipyplot does not render on the website.

As a workaround, I would like to save the output as a png file and then add it to my blog via markdown.

Unfortunately, I can't figure out how to save the output and I don't see it written anywhere in the documentation for how to save the output.

Once again, greatly appreciate the work you do.

karolzak commented 4 years ago

True, this is not well documented but there's a way to make those images render correctly in a website. I assume you're using images collection in form of local URLs (that's why it's not rendering correctly in the website). One thing you can try (when you want to export that notebook as HTML or render as .ipynb) is to use force_b64 flag and set it to True:

plot_images(images, labels, force_b64=True)

With that you will enforce images to get converted into base64 strings and injected into HTML. That way you can either render the whole .ipynb notebook or export notebook as HTML and post it on your website. Let me know if that works for you.

educatorsRlearners commented 4 years ago

@karolzak I could have sworn I tried that solution but it looks like I didn't save the changes before pushing to git.

Needless to say, it works like a charm :+1: Cheers!

karolzak commented 4 years ago

Just a food for thoughts. One potential option for saving output as image file is to rely on some external tool like webkit. Here's a python wrapper for it: https://pypi.org/project/imgkit/ This would be an optional solution for people ok to install some additional dependencies. In this case of course the output would be completely non interactive (static image) so it would not work great for plot_class_tabs function output. Other option would be to just extract output HTML as a separate file or even a string that can be injected somewhere else. Something to consider in future iterations..

karolzak commented 3 years ago

Closing this thread as we found a workaround for this problem but discussion about saving outputs as image files will continue here #20