Unified API and style for Python plotting libraries.
๐ก See gallery for more examples.
Recent stable version (without any plotting library):
pip install "uplot @ git+https://github.com/makarovdi/uplot.git@main"
To automatically install all optional dependencies (matplotlib, plotly, ...):
pip install "uplot[all] @ git+https://github.com/makarovdi/uplot.git@main"
If you need only matplotlib
support:
pip install "uplot[matplotlib] @ git+https://github.com/makarovdi/uplot.git@main"
๐ก Replace
[matplotlib]
with[plotly5]
for plotly-only installation
๐ข Highly configurable.
๐ข Good documentation and a lot of ready-to-use recipes (e.g. on StackOverflow).
๐ก Common API (MATLAB legacy).
๐ด Limited interactivity (especially for Jupyter).
๐ด API, behavior and parameter names are inconsistent (e.g. plt.xlim and axis.set_xlim).
๐ด Slow and limited 3D rendering.
๐ข Very good interactivity.
๐ข Native compatibility with Jupyter.
๐ข Possibility to save interactive plot (html-file).
๐ข Fast and interactive 3D plot.
๐ด Not well documented (a lot of parameters, small amount of examples).
๐ด High memory consumption (limited number of plots in Jupyter).
๐ด Some expected API functions are missing (e.g. imshow).
๐ด 3D and 2D axis parameters are not unified (e.g. layout.xaxis doesn't work for 3D).
The plugin system allows extending uplot
for visualizing custom objects.
For example, the DataFrame
plugin enables this code:
import uplot
import pandas as pd
car_crashes = pd.read_csv(
'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/car_crashes.csv'
)
fig = uplot.figure()
fig.plot(car_crashes[['total', 'speeding', 'alcohol', 'no_previous']])
fig.show()
To implement the plugin, you can follow this structure:
import numpy as np
import pandas as pd
import uplot.plugin as plugin
class DataFramePlugin(plugin.IPlotPlugin):
def extract_data(self, obj: pd.DataFrame) -> list[plugin.PlotData]:
data = []
for name in obj.columns:
if not np.issubdtype(obj.dtypes[name], np.number): continue
y = obj[name].values
x = np.arange(len(y))
data.append(plugin.PlotData(x=x, y=y, name=name.replace('_', ' ').title()))
return data
plugin.register(pd.DataFrame, handler=DataFramePlugin())
๐ก Check
test/plugin.py
for a more advanced plugin example.
Adding a new plotting library is straightforward. Implement two interfaces IPlotEngine
and IFigure
:
import uplot
from uplot import IPlotEngine, IFigure
class MyEngine(IPlotEngine):
...
def figure(self, ...) -> MyFigure: ...
class MyFigure(IFigure):
def plot(self, ...): ...
def scatter(self, ...): ...
...
# register the engine
uplot.engine.register(MyEngine(), name='test')
Then use it in the regular way:
import uplot
fig = uplot.figure(engine='test')
fig.plot(...)
fig.show()
Standalone | JupyterLabv4.0.6-v4.2.3 |
Jupyter Notebook 7.0-7.2 |
|
---|---|---|---|
matplotlib3.7-3.9 |
gui ๐ขsave image ๐ข |
inline ๐ขipympl ๐ข |
inline ๐ขipympl ๐ข |
plotly5.16-5.22 |
chromium ๐ขsave image ๐ข |
๐ข | ๐ข |
Python
โฅ 3.10numpy
โฅ 1.21v2.0 supported
pillow
โฅ 10.2
matplotlib
โฅ 3.7plotly
โฅ 5.17
This software is licensed under the BSD-3-Clause
license.
See the LICENSE file for details.
Check the plan for new features here.