Created
June 19, 2020 21:06
-
-
Save rileypeterson/8124455b6c3c47bbc58cfe25a499d61f to your computer and use it in GitHub Desktop.
Insert an image into html img tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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