Registry / data / mpld3
library0.5.12pypypi✓ verified 22d ago

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.

pip install mpld3
INSTALL
IMPORT
SIG · MPLD3
M
mpld3
datapythonv0.5.12
Install
8.1s avg
Import
2881ms
Disk
183MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.12 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.948s · 180.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.1s · import 2.814s · 172MB
183MB installed
● package 183MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mpld3
import mpld3
matplotlib.pyplot
import matplotlib.pyplot as plt
import matplotlib.pyplot
Using 'plt' as an alias is the conventional and recommended practice for matplotlib.

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)
Debug
Known issues
gotchaWhen updating mpld3, particularly in Jupyter Notebooks, cached JavaScript libraries can cause unexpected behavior. The notebook might still use older versions of the JS library, even if the Python package is updated.
fix
Clear all output in the notebook (Cell -> All Output -> Clear), save the notebook, close the window, and then re-open it.
affects: All versions
gotchampld3 is not designed for large datasets (plots with more than a few thousand elements). Performance for interactive features will degrade significantly due to its reliance on HTML SVG, which is not optimized for big data visualization.
fix
For large datasets, consider specialized tools that leverage data summarization or GPU acceleration, such as Bokeh or other dedicated big data visualization libraries.
affects: All versions
deprecatedImporting mpld3 can trigger numerous deprecation warnings from `ipywidgets` in newer Python environments (e.g., Python 3.5+). This is due to broad warning filters applied by mpld3's internal `utils.py` module.
fix
This is a known issue (GitHub #346) with no direct user-level fix provided; it requires an internal patch to mpld3's warning handling. Users might need to filter warnings manually if they find them disruptive.
affects: 0.2+
gotchampld3's compatibility documentation explicitly mentions Python versions 2.6-2.7 and 3.3-3.4. While it may run on newer Python 3 versions (e.g., 3.5+), these versions are not officially guaranteed to be fully supported or tested, which could lead to unexpected behavior or incompatibilities.
fix
Refer to the official documentation and GitHub issues for current compatibility. If encountering issues with newer Python versions, consider using a compatible Python environment or checking for community workarounds.
affects: <=0.5.12
gotchaSome advanced Matplotlib features, such as custom widgets or intricate tick label formatting (e.g., `ax.xaxis.set_ticklabels()`), may not be fully supported or accurately translated into the D3.js output, limiting full interactive parity with native Matplotlib figures.
fix
Users may need to explore mpld3's plugin framework to implement custom interactive behaviors or adjust expectations for direct Matplotlib feature translation.
affects: All versions
Errors
Common errors & fixes
TypeError: Object of type 'ndarray' is not JSON serializable
This error occurs when `mpld3` attempts to serialize a Matplotlib figure containing NumPy arrays or other complex objects that are not directly JSON serializable.
fix
Ensure that any data passed to Matplotlib plotting functions is converted to a standard Python list before being rendered by `mpld3`. For instance, convert NumPy arrays using `.tolist()` if applicable, or ensure custom objects have a JSON serialization method. If using a specific plugin, verify its compatibility with the data types.
mpld3.show() freezes/does not display in Jupyter Notebook / mpld3.display() not showing graph
`mpld3.show()` is intended for stand-alone scripts to open a new browser window, which often conflicts with the Jupyter/IPython Notebook environment already running in a browser. In notebooks, `mpld3.display()` or `mpld3.enable_notebook()` should be used.
fix
In Jupyter Notebooks, use `mpld3.display(fig)` to render a single figure, or `mpld3.enable_notebook()` (after `%matplotlib inline`) to automatically render all subsequent Matplotlib figures interactively. If issues persist after an update, clear all notebook output, save, close, and re-open the notebook.
AttributeError: module 'matplotlib.dates' has no attribute '_SwitchableDateConverter'
This error typically indicates an incompatibility between the `mpld3` version and a newer version of Matplotlib, specifically concerning how date handling or internal Matplotlib modules are structured. `mpld3` is in maintenance mode and may not support the latest Matplotlib changes.
fix
Downgrade Matplotlib to a version known to be compatible with `mpld3` (e.g., Matplotlib 1.3+ to 2.2.2 as per `mpld3` documentation). Alternatively, check GitHub issues for potential patches or workarounds if a specific newer Matplotlib feature is causing the conflict.
AttributeError: 'list' object has no attribute 'canvas'
This error arises when an `mpld3` function that expects a Matplotlib `Figure` object (like `mpld3.fig_to_html()` or `mpld3.save_html()`) is instead passed a list of Matplotlib artists or raw data.
fix
Ensure that you are passing an actual `matplotlib.figure.Figure` object to `mpld3` functions. If you've created plots using `plt.plot()`, make sure you explicitly capture the figure, e.g., `fig = plt.figure()` and then pass `fig` to `mpld3` functions.
Upgrade
Version history
0.5.12latest on PyPI · released Nov 5, 2025
Audit
Dependencies
matplotlibrequiredRequired for creating plots to be converted.
jinja2requiredUsed for templating the HTML output.
ipythonoptionalOptional dependency for enhanced functionality within Jupyter Notebooks.
Agent activity
9 hits · last 30 days
node
8
Resources