HOSTING

Share a Matplotlib chart as a web page

A PNG in an email loses its context, and a notebook needs Python to open. Save the figure as SVG, put it in one HTML file with your notes, upload it, and send a link that opens in any browser.

4 min read·

A chart pasted into an email or chat becomes an image with no caption, no source and no way to update it. A web page can hold the chart, the explanation and the numbers behind it, and the link stays the same when you rerun the analysis.

Save the figure as SVG

  • ✓Use the Agg backend when the script runs without a display: matplotlib.use("Agg") before importing pyplot.
  • ✓buf = io.StringIO(); fig.savefig(buf, format="svg", bbox_inches="tight"); svg = buf.getvalue() gives the figure as text. bbox_inches="tight" trims the empty margin.
  • ✓By default Matplotlib draws SVG text as outlines (svg.fonttype is "path"), so labels look the same on every device without the font installed. Tested on Matplotlib 3.11.2.
  • ✓The SVG output starts with an XML declaration and a DOCTYPE line. Keep only the part from <svg onward: svg = svg[svg.index("<svg"):].

Put it in one HTML file

  • ✓Start with <!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">, add a title and your notes, then paste the svg string where the chart goes.
  • ✓Add svg { max-width: 100%; height: auto; } in a <style> block so the chart shrinks to fit a phone screen.
  • ✓Several figures go in the same file: one <svg> block per figure, each under its own heading.
  • ✓For a photo-like plot with many points, such as a dense scatter or an image, SVG files get large. Save that figure as PNG instead (fig.savefig(b, format="png", dpi=150) into an io.BytesIO), base64-encode it and use <img src="data:image/png;base64,...">. The file stays self-contained either way.

Upload it and send the link

Drag the HTML file onto the FileShare Pro dashboard and copy the link. Viewers need no account and nothing to install. Shared pages carry a noindex tag, so work-in-progress results do not show up in search. On Pro you can add a password: password-protecting an HTML page.

Turn on comments and readers can leave a note on the page after typing a name, so questions about an axis or an outlier stay next to the chart. The view count shows whether the person you sent it to has opened it.

Need hover and zoom? Plotly writes an interactive chart to one HTML file: sharing a Plotly chart as a link. For a table of the numbers: sharing a pandas DataFrame as a web page.

Update the chart without a new link

Rerun the script and upload the new HTML over the old file. The link stays the same and the previous version is kept in history: updating a shared link without changing it.

Frequently asked

How do I share a Matplotlib chart as a link?

Save the figure with savefig(format="svg") into a string, paste the <svg> part into an HTML file with a charset line, upload it to FileShare Pro and send the link. It opens in any browser.

SVG or PNG?

SVG for line, bar and most charts: it stays sharp at any zoom and the file is small. PNG for plots with many thousands of points or images, where SVG files get large.

Will the labels use the right font?

Yes. Matplotlib draws SVG text as outlines by default, so viewers see the same lettering without having the font installed.

Can viewers zoom or hover over points?

Browser zoom works and SVG stays sharp, but there are no tooltips. For hover and pan, export the chart with Plotly instead.

Is it free?

Yes. The free plan hosts up to 50 files of up to 100 MB each, with view counts and comments included. Password-protected links are on Pro.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free