daily log 11.23.20

less than 1 minute read

Section 3: Scatterplots

  1. I set up my data
  2. I set up my layout
  3. I pass both to a figure object
# IMPORT PACKAGES
import numpy as np
import plotly.offline as pyo
import plotly.graph_objs as go

# CREATE SOME FAKE DATA
np.random.seed(42)
random_x = np.random.randint(1,101,100)
random_y = np.random.randint(1,101,100)

# CREATE THE MOST BASIC PLOT
data = [go.Scatter(x=random_x,y=random_y, mode="markers")]
pyo.plot(data,filename='scatter.html')

# PLOT V2: Custom title and labels!
data = [go.Scatter(x=random_x,y=random_y, mode="markers")]
layout = go.Layout(title='First plot!',
                  xaxis={'title': 'XAXIS'},
                  yaxis=dict(title='myYAXIS'),
                  hovermode='closest')

fig = go.Figure(data=data,layout=layout)
pyo.plot(fig,filename='scatter.html')

# PLOT V3: Custom markers!
data = [go.Scatter(x=random_x,
                   y=random_y, 
                   mode="markers",
                   marker=dict(
                      size=12,
                      color='rgb(51,204,153)',
                      symbol='pentagon',
                      line = {'width': 2}))]
layout = go.Layout(title='First plot!',
                  xaxis={'title': 'XAXIS'},
                  yaxis=dict(title='myYAXIS'),
                  hovermode='closest')

fig = go.Figure(data=data,layout=layout)
pyo.plot(fig,filename='scatter.html')