Line scatter plots

We can also create some more informative plots, such as a line scatter plot. Let's look at an example. Create a script called line_scatter_plot.py and write the following content in it:

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

x_axis = np.linspace(0, 1, 50)
y0_axis = np.random.randn(50)+5
y1_axis = np.random.randn(50)
y2_axis = np.random.randn(50)-5

trace0 = go.Scatter(x = x_axis,y = y0_axis,mode = 'markers',name = 'markers')
trace1 = go.Scatter(x = x_axis,y = y1_axis,mode = 'lines+markers',name = 'lines+markers')
trace2 = go.Scatter(x = x_axis,y = y2_axis,mode = 'lines',name = 'lines')

data_sets = [trace0, trace1, trace2]
plotly.offline.plot(data_sets, filename='line_scatter_plot.html')

Run the script and you will get the following output:

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

The output is as follows:

In the preceding example, we imported plotly, as well as the numpy module. Then we generated some random values for the  x-axis and also for three different y-axes. After that, we put that data in the created trace object and, finally, put that dataset in plotly's offline function. Then we get the output in the format of scatter as well as line. The output file of this example is saved with the name line_scatter_plot.html in your current directory.

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

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