Scatter Plot Creation with Plotly and Numpy

  • Share this:

Code introduction


This function creates a scatter plot. It generates x and y coordinate data using numpy and then plots it using Plotly's graph_objects module.


Technology Stack : Plotly, Numpy

Code Type : Plotly graphics drawing

Code Difficulty : Intermediate


                
                    
import plotly.graph_objects as go
import numpy as np

def create_scatter_plot(x, y):
    # Create a trace
    trace = go.Scatter(x=x, y=y, mode='markers')

    # Create data
    data = [trace]

    # Plot the data
    fig = go.Figure(data=data)

    # Update layout
    fig.update_layout(title='Scatter Plot Example', xaxis_title='X Axis', yaxis_title='Y Axis')

    # Display the plot
    fig.show()                
              
Tags: