render_point_cloud#

crispy.visualize.render_point_cloud(cube, savename=None, showfig=False, bins=15, vmin=None, vmax=None, cmap='magma_r', z_stretch=1, size=3, fig=None, cbar_label='')[source]#

Render a 3D scatter plot from a 3D data cube with efficient visualization.

The function generates a 3D point cloud visualization from a 3D numpy array, coloring the points based on their values and assigning opacity based on percentile bins. A single colorscale spans all bins.

Parameters:
  • cube (numpy.ndarray) – A 3D numpy array of float values to visualize. NaN values are ignored.

  • savename (str, optional) – Path to save the interactive HTML file. If None, the figure is not saved. Default is None.

  • showfig (bool, optional) – Whether to display the figure interactively. Default is False.

  • bins (int, optional) – Number of percentile bins for dividing the data. Default is 5.

  • vmin (float, optional) – Minimum value for normalization. If None, the 10th percentile of the data is used. Default is None.

  • vmax (float, optional) – Maximum value for normalization. If None, the 99th percentile of the data is used. Default is None.

  • cmap (str, optional) – Colormap for the data points. Uses Plotly-compatible colormap names. Default is “magma_r”.

  • z_stretch (float, optional) – Scaling factor for the Z-axis to modify aspect ratio. Default is 1.

  • size (int, optional) – The marker (i.e., point) size used to render the point cloud. Default is 2

  • fig (plotly.graph_objects.Figure, optional) – Existing Plotly figure to add the scatter plot to. If None, a new figure is created. Default is None.

  • cbar_label (str, optional) – Label for the colorbar. Default is an empty string.

Returns:

The Plotly figure object containing the 3D scatter plot.

Return type:

plotly.graph_objects.Figure

Notes

  • Points outside the range [vmin, vmax] are excluded.

  • Percentile bins determine point opacity for better depth visualization.

  • A shared color axis is used for consistency across bins.

Examples

>>> import numpy as np
>>> X, Y, Z = np.mgrid[-1:1:30j, -1:1:30j, -1:1:30j]
>>> cube = np.sin(np.pi * X) * np.cos(np.pi * Z) * np.sin(np.pi * Y)
>>> render_point_cloud(cube, showfig=True, bins=4)