Skip to content

Instantly share code, notes, and snippets.

@alexlenail
Created January 22, 2026 00:26
Show Gist options
  • Select an option

  • Save alexlenail/c58929365ec324bd3e16ed214e86b726 to your computer and use it in GitHub Desktop.

Select an option

Save alexlenail/c58929365ec324bd3e16ed214e86b726 to your computer and use it in GitHub Desktop.
from pathlib import Path
from IPython.display import display, Markdown
def save_and_display_fig(fig, output_stem):
output_stem = Path(output_stem)
output_stem.parent.mkdir(parents=True, exist_ok=True)
fig.savefig(output_stem.with_suffix(".pdf"), bbox_inches="tight")
fig.savefig(output_stem.with_suffix(".svg"), bbox_inches="tight")
plt.close(fig)
display(Markdown(f"![{output_stem.name}]({output_stem.with_suffix('.svg')})"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment