Scatter Plot Generator with HoloViews

  • Share this:

Code introduction


This function creates a scatter plot using the HoloViews library, demonstrating it with a randomly generated dataset. It accepts a DataFrame and column names for the x-axis and y-axis as inputs.


Technology Stack : HoloViews, Pandas, NumPy

Code Type : Function

Code Difficulty : Intermediate


                
                    
def create_random_scatter_plot(data, x_col, y_col):
    import numpy as np
    import pandas as pd
    import holoviews as hv
    from holoviews import opts

    # Generate a random DataFrame
    np.random.seed(0)
    data = pd.DataFrame({
        x_col: np.random.randn(100),
        y_col: np.random.randn(100)
    })

    # Create a scatter plot using HoloViews
    scatter_plot = hv.Scatter(data, x=x_col, y=y_col).opts(
        tools=['pan', 'zoom', 'box_zoom', 'reset'],
        width=600,
        height=400
    )

    return scatter_plot