Created
February 28, 2018 16:00
-
-
Save jbn/58de053e81ad305621dee1e1bf272232 to your computer and use it in GitHub Desktop.
Extract for attempted David assist
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
import matplotlib.pyplot as plt | |
from ipykernel.pylab.backend_inline import flush_figures | |
from IPython.display import display, clear_output, SVG | |
def replot_as_svg(fig=None, **adjustments): | |
""" | |
Take a given matplotlib figure and write it as an embeddable SVG. | |
:param fig: the matplotlib figure or None for implicit use of plt.gcf() | |
:return: an IPython SVG object. | |
""" | |
if fig is None: | |
fig = plt.gcf() | |
if adjustments: | |
fig.subplots_adjust(**adjustments) | |
buf = BytesIO() | |
fig.savefig(buf, format="svg") | |
plt.close() | |
buf.seek(0) | |
clear_output(wait=True) | |
svg = SVG(data=hatch_safe_svg(buf.read())) | |
display(svg) | |
return svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment