You can download this code by clicking the button below.
This code is now available for download.
This function uses the GraphObjects module from Plotly to generate a scatter plot. It takes two lists, x and y, as inputs, which represent the data points for the x and y axes of the chart. The function creates a scatter plot and sets the title and axis labels.
Technology Stack : Plotly, GraphObjects, Numpy
Code Type : Chart generation
Code Difficulty : Intermediate
import plotly.graph_objects as go
import numpy as np
def generate_scatter_plot(x, y):
# Create a trace
trace = go.Scatter(x=x, y=y, mode='markers')
# Create layout
layout = go.Layout(title='Scatter Plot', xaxis={'title': 'X Values'}, yaxis={'title': 'Y Values'})
# Create figure
fig = go.Figure(data=[trace], layout=layout)
# Show plot
fig.show()
# Example usage
x = np.random.rand(10)
y = np.random.rand(10)
generate_scatter_plot(x, y)