Skip to content

Instantly share code, notes, and snippets.

@rileypeterson
Created June 19, 2020 21:06
Show Gist options
  • Save rileypeterson/8124455b6c3c47bbc58cfe25a499d61f to your computer and use it in GitHub Desktop.
Save rileypeterson/8124455b6c3c47bbc58cfe25a499d61f to your computer and use it in GitHub Desktop.
Insert an image into html img tag
from io import BytesIO
import matplotlib.pyplot as plt
import base64
b = BytesIO()
plt.plot([1,2,3])
plt.savefig(b)
b64_img_str = base64.encodebytes(b.getvalue()).decode()
# In js
# $("#graph1").attr("src", "data:image/png;base64, ".concat(b64_img_str));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment