Creating a Scatter Plot with Plotly

  • Share this:

Code introduction


This function creates a scatter plot to visualize the relationship between two numerical arrays. It accepts two parameters x and y, which should be arrays of the same length.


Technology Stack : The packages and technologies used in the code include Plotly's GraphObjects module and the NumPy library.

Code Type : Function

Code Difficulty : Intermediate


                
                    
import plotly.graph_objects as go
import numpy as np

def create_scatter_plot(x, y):
    fig = go.Figure(data=[go.Scatter(x=x, y=y, mode='markers')])
    fig.update_layout(title='Scatter Plot Example', xaxis_title='X Values', yaxis_title='Y Values')
    fig.show()