Generating a 3D Surface Plot with HoloViews

  • Share this:

Code introduction


This function accepts data points (x, y, z) in a 3D space and generates a 3D surface plot using the HoloViews library.


Technology Stack : HoloViews, NumPy

Code Type : 3 D graphics visualization

Code Difficulty : Intermediate


                
                    
import numpy as np
import holoViews as hv
from holoviews import opts

def plot_surface_3d(x, y, z):
    """
    This function generates a 3D surface plot from given x, y, and z data.

    Args:
        x (numpy.ndarray): The x-coordinates of the data points.
        y (numpy.ndarray): The y-coordinates of the data points.
        z (numpy.ndarray): The z-coordinates of the data points.

    Returns:
        holoviews.core.element.ComputedElement: A 3D surface plot.
    """
    data = np.column_stack((x, y, z))
    surf = hv.Surface(data).opts(
        colorbar=True,
        tools=['hover', 'pan', 'zoom', 'reset'],
        width=600,
        height=400
    )
    return surf