D3 Viewer for Matplotlib

0.5.12 · maintenance · verified Mon Apr 13

mpld3, currently at version 0.5.12, bridges Matplotlib's powerful plotting capabilities with D3.js for interactive web visualizations. It provides a straightforward API to export Matplotlib graphics to HTML, suitable for web pages, blogs, or Jupyter notebooks. The project's development is in maintenance mode, with maintainers reviewing pull requests but having limited time for issue resolution.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple Matplotlib plot and then use `mpld3.show()` to render it as an interactive D3.js visualization in your default web browser. Alternatively, `mpld3.fig_to_html()` can generate the HTML string for embedding.

import matplotlib.pyplot as plt
import mpld3

fig, ax = plt.subplots()
ax.plot([3, 1, 4, 1, 5], 'ks-', mec='w', mew=5, ms=20)
ax.set_title("My Interactive Plot")

# To display in a browser:
mpld3.show(fig)

# To get HTML string:
# html_output = mpld3.fig_to_html(fig)
# print(html_output)

view raw JSON →