Scatter plots

Create a script called scatter_plot_plotly.py and write the following content in it:

import plotly
import plotly.graph_objs as go
import numpy as np

x_axis = np.random.randn(100)
y_axis = np.random.randn(100)

trace = go.Scatter(x=x_axis, y=y_axis, mode = 'markers')
data_set = [trace]
plotly.offline.plot(data_set, filename='scatter_plot.html')

Run the script and you will get the following output:

student@ubuntu:~/work$ python3 scatter_plot_plotly.py

The output is as follows:

In the preceding example, we imported plotly and then created random data by using numpy and, for that, import the numpy module in your script. After generating the dataset, we created one object named trace and inserted our numerical data in it to be scattered. Then, finally, we place the data in the trace object into the plotly.offline.plot() function to get the scatter plot of data. Like our first sample graph, the output of this example is also saved in HTML format and displayed in your default web browser.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset