In [22]:
import plotly.plotly as py
import plotly.graph_objs as go

In [23]:
# Create random data with numpy
import numpy as np

Simple Scatter Plot


In [24]:
N = 100
random_x = np.random.randn(N)
random_y = np.random.randn(N)

In [25]:
# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

In [26]:
data = [trace]

In [27]:
# Plot and embed in Jupyter notebook!
py.iplot(data, filename='examples/basic-scatter')


Out[27]:

Line Scatter Plot


In [14]:
N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5

In [15]:
# Create traces
trace0 = go.Scatter(
    x = random_x,
    y = random_y0,
    mode = 'markers',
    name = 'markers'
)
trace1 = go.Scatter(
    x = random_x,
    y = random_y1,
    mode = 'lines+markers',
    name = 'lines+markers'
)
trace2 = go.Scatter(
    x = random_x,
    y = random_y2,
    mode = 'lines',
    name = 'lines'
)

In [16]:
data = [trace0, trace1, trace2]
py.iplot(data, filename='examples/multiple-trace-scatter')


Out[16]:

Style Scatter Plot


In [28]:
N = 500

In [29]:
trace0 = go.Scatter(
    x = np.random.randn(N),
    y = np.random.randn(N)+2,
    name = 'Above',
    mode = 'markers',
    marker = dict(
        size = 10,
        color = 'rgba(152, 0, 0, .8)',
        line = dict(
            width = 2,
            color = 'rgb(0, 0, 0)'
        )
    )
)

In [30]:
trace1 = go.Scatter(
    x = np.random.randn(N),
    y = np.random.randn(N)-2,
    name = 'Below',
    mode = 'markers',
    marker = dict(
        size = 10,
        color = 'rgba(255, 182, 193, .9)',
        line = dict(
            width = 2,
        )
    )
)

In [31]:
data = [trace0, trace1]

In [32]:
layout = dict(title = 'Styled Scatter',
              yaxis = dict(zeroline = False),
              xaxis = dict(zeroline = False)
             )

In [33]:
fig = dict(data=data, layout=layout)

In [34]:
py.iplot(fig, filename='examples/styled-scatter')


Out[34]:

In [37]:
trace1 = go.Scatter(
    y = np.random.randn(500),
    mode='markers',
    marker=dict(
        size=16,
        color = np.random.randn(500), #set color equal to a variable
        colorscale='Viridis',
        showscale=True
    )
)
data = [trace1]

In [38]:
py.iplot(data, filename='examples/scatter-plot-with-colorscale')


Out[38]:

In [ ]: