Matplotlib Implementation
This module provides Matplotlib visualization implementation for NURBS-Python.
Note
Please make sure that you have installed matplotlib package before using this visualization module.
Class Reference
- class geomdl.visualization.VisMPL.VisConfig(**kwargs)
Bases:
VisConfigAbstractConfiguration class for Matplotlib visualization module.
This class is only required when you would like to change the visual defaults of the plots and the figure, such as hiding control points plot or legend.
The
VisMPLmodule has the following configuration variables:ctrlpts(bool): Control points polygon/grid visibility. Default: Trueevalpts(bool): Curve/surface points visibility. Default: Truebbox(bool): Bounding box visibility. Default: Falselegend(bool): Figure legend visibility. Default: Trueaxes(bool): Axes and figure grid visibility. Default: Truelabels(bool): Axis labels visibility. Default: Truetrims(bool): Trim curves visibility. Default: Trueaxes_equal(bool): Enables or disables equal aspect ratio for the axes. Default: Truefigure_size(list): Size of the figure in (x, y). Default: [10, 8]figure_dpi(int): Resolution of the figure in DPI. Default: 96trim_size(int): Size of the trim curves. Default: 20alpha(float): Opacity of the evaluated points. Default: 1.0
There is also a
debugconfiguration variable which currently adds quiver plots to 2-dimensional curves to show their directions.The following example illustrates the usage of the configuration class.
1# Create a curve (or a surface) instance 2curve = NURBS.Curve() 3 4# Skipping degree, knot vector and control points assignments 5 6# Create a visualization configuration instance with no legend, no axes and set the resolution to 120 dpi 7vis_config = VisMPL.VisConfig(legend=False, axes=False, figure_dpi=120) 8 9# Create a visualization method instance using the configuration above 10vis_obj = VisMPL.VisCurve2D(vis_config) 11 12# Set the visualization method of the curve object 13curve.vis = vis_obj 14 15# Plot the curve 16curve.render()
Please refer to the Examples Repository for more details.
- is_notebook()
Detects if Jupyter notebook GUI toolkit is active
return: True if the module is running inside a Jupyter notebook rtype: bool
- static save_figure_as(fig, filename)
Saves the figure as a file.
- Parameters:
fig – a Matplotlib figure instance
filename – file name to save
- static set_axes_equal(ax)
Sets equal aspect ratio across the three axes of a 3D plot.
Contributed by Xuefeng Zhao.
- Parameters:
ax – a Matplotlib axis, e.g., as output from plt.gca().
- class geomdl.visualization.VisMPL.VisCurve2D(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for 2D curves
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the 2D curve and the control points polygon.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisCurve3D(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for 3D curves.
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the 3D curve and the control points polygon.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisSurfScatter(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for surfaces.
Wireframe plot for the control points and scatter plot for the surface points.
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the surface and the control points grid.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisSurfWireframe(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for surfaces.
Scatter plot for the control points and wireframe plot for the surface points.
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the surface and the control points grid.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisSurface(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for surfaces.
Wireframe plot for the control points and triangulated plot (using
plot_trisurf) for the surface points. The surface is triangulated externally usingutilities.make_triangle_mesh()function.- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Animates the surface.
This function only animates the triangulated surface. There will be no other elements, such as control points grid or bounding box.
- Keyword arguments:
colormap: applies colormap to the surface
Colormaps are a visualization feature of Matplotlib. They can be used for several types of surface plots via the following import statement:
from matplotlib import cmThe following link displays the list of Matplolib colormaps and some examples on colormaps: https://matplotlib.org/tutorials/colors/colormaps.html
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the surface and the control points grid.
- Keyword arguments:
colormap: applies colormap to the surface
Colormaps are a visualization feature of Matplotlib. They can be used for several types of surface plots via the following import statement:
from matplotlib import cmThe following link displays the list of Matplolib colormaps and some examples on colormaps: https://matplotlib.org/tutorials/colors/colormaps.html
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisVolume(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for volumes.
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Plots the volume and the control points.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract
- class geomdl.visualization.VisMPL.VisVoxel(config=<geomdl.visualization.VisMPL.VisConfig object>, **kwargs)
Bases:
VisAbstractMatplotlib visualization module for voxel representation of the volumes.
- add(ptsarr, plot_type, name='', color='', idx=0)
Adds points sets to the visualization instance for plotting.
- Parameters:
ptsarr (list, tuple) – control or evaluated points
plot_type (str) – type of the plot, e.g. ctrlpts, evalpts, bbox, etc.
name (str) – name of the plot displayed on the legend
color (int) – plot color
color – plot index
- animate(**kwargs)
Generates animated plots (if supported).
If the implemented visualization module supports animations, this function will create an animated figure. Otherwise, it will call
render()method by default.
- clear()
Clears the points, colors and names lists.
- property ctrlpts_offset
Defines an offset value for the control points grid plots
Only makes sense to use with surfaces with dense control points grid.
- Getter:
Gets the offset value
- Setter:
Sets the offset value
- Type:
float
- render(**kwargs)
Displays the voxels and the control points.
- size(plot_type)
Returns the number of plots defined by the plot type.
- Parameters:
plot_type (str) – plot type
- Returns:
number of plots defined by the plot type
- Return type:
int
- property vconf
User configuration class for visualization
- Getter:
Gets the user configuration class
- Type:
vis.VisConfigAbstract