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:
geomdl.vis.VisConfigAbstract
Configuration 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
VisMPL
module 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
debug
configuration 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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Create a curve (or a surface) instance curve = NURBS.Curve() # Skipping degree, knot vector and control points assignments # Create a visualization configuration instance with no legend, no axes and set the resolution to 120 dpi vis_config = VisMPL.VisConfig(legend=False, axes=False, figure_dpi=120) # Create a visualization method instance using the configuration above vis_obj = VisMPL.VisCurve2D(vis_config) # Set the visualization method of the curve object curve.vis = vis_obj # Plot the curve curve.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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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 cm
The 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.
-
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 cm
The 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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
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:
geomdl.vis.VisAbstract
Matplotlib 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.
-
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
-
vconf
¶ User configuration class for visualization
Getter: Gets the user configuration class Type: vis.VisConfigAbstract
-