Random Surface Plot Generation with Numpy and HoloViews

  • Share this:

Code introduction


This function generates random data using numpy and then creates a 3D surface plot with HoloViews, with some style settings applied.


Technology Stack : numpy, HoloViews

Code Type : Function

Code Difficulty : Intermediate


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

def plot_random_surface(n=10):
    """
    Plots a random surface using numpy and HoloViews.
    """
    x = np.sort(15 * np.random.rand(n), axis=0)
    y = np.sort(15 * np.random.rand(n), axis=0)
    x, y = np.meshgrid(x, y)
    z = np.cos(np.sqrt(x**2 + y**2))

    plot = hv.Surface((x, y, z)).relabel('Random Surface')
    plot = plot * opts.Surface(Contours=10)
    hv.render(plot)