Created
February 18, 2021 02:33
-
-
Save nlothian/6520cf8b35b4ff69e3148806db6f17f5 to your computer and use it in GitHub Desktop.
Convert a matplotlib graph to base64, suitable for inclusing as a data: url in HTML.
This file contains 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
def build_GRAPHS_MD(fig): | |
# encode as base64 for markdown display | |
buf = io.BytesIO() | |
fig.savefig(buf, format='png') | |
buf.seek(0) | |
b64str = base64.b64encode(buf.read()).decode('ascii') | |
plt.close() | |
markdown_txt = f""" | |
![Distribution](data:image/png;base64,{b64str}) | |
` ` | |
` ` | |
""" | |
return markdown_txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment