Choosing your plotting backend#
DiffeRT supports various backends for plotting scenes and related-objects:
VisPy, a high-performance interactive visualization library that leverages the power of modern GPUs through OpenGL. Installing VisPy on its own is not sufficient and you will need at least one of the VisPy backends to be installed: https://vispy.org/installation.html. If available, VisPy will be used by default as it provides the best user experience, especially on large scenes.
Matplotlib, a very user-friendly and popular tool for creating plots in Python.
Plotly, a Python library for building beautiful interactive plots for the web.
Additionally, all those backends can be used within Jupyter notebooks.
For VisPy, you will need jupyter_rfb and a recent JupyterLab installation,
that you can obtain with pip install differt[jupyter].
from differt.geometry import TriangleMesh
mesh_file = "bruxelles.obj"
mesh = TriangleMesh.load_obj(mesh_file)
VisPy#
VisPy is the default plotting backend, and supports all plotting utilities.
Because this is the default backend, you do not have to specify it, unless you changed the default backend.
Pros#
Performances;
Has a relatively good documentation;
Integrates well with Qt applications;
Implements all plotting utilities.
Cons#
Does not support interactive offline rendering (i.e., a static snapshot is shown);
Requires an additional and possibly large dependency (e.g., PyQt6).
canvas = mesh.plot(backend="vispy")
canvas
Matplotlib#
Matplotlib is probably the most-used Python plotting library.
Pros#
Has excellent online documentation;
Can be integrated with Qt applications;
Support a lot of configuration options and output formats;
Simple and user-friendly API.
Cons#
Does not support interactive offline rendering (i.e., a static snapshot is shown);
Poor 3D graphics support;
Interactive and 3D plots are slow.
%matplotlib widget
fig = mesh.plot(
backend="matplotlib",
alpha=0.5,
shade=True,
linewidth=0.2,
antialiased=True,
)
fig.gca().axis("equal");
Plotly#
Plotly is a JavaScript-based plotting library that can produce beautiful plots in very few lines of codes.
Pros#
Has excellent interactive mode;
Provides beautiful plots with almost zero-configuration needed;
Supports interactive offline rendering (i.e., plots can be fully contained in HTML pages).
Cons#
Not-so-good online documentation (i.e., many functions lack usage examples);
Does not export so well to raster or vector formats (PNG, PDF, etc.);
Slow 3D graphics and relatively glitchy.
fig = mesh.plot(backend="plotly", opacity=0.5)
fig