Skip to content

Instantly share code, notes, and snippets.

@limitpointinf0
Last active May 4, 2018 19:02
Show Gist options
  • Save limitpointinf0/ebcf9ae89c3670155f44170cac140831 to your computer and use it in GitHub Desktop.
Save limitpointinf0/ebcf9ae89c3670155f44170cac140831 to your computer and use it in GitHub Desktop.
Easy Plotly
import plotly as py
import plotly.graph_objs as go
import numpy as np
#py.tools.set_credentials_file(username='user_name', api_key='api_key')
py.offline.init_notebook_mode(connected=True)
def make_trace(x, y, mode='markers', pltname=None, shape='spline'):
trace = go.Scatter(x = x, y = y, mode = mode, name = pltname, line = dict(shape=shape))
return trace
def plotly_plot(traces, title=None, xtitle=None, ytitle=None, mode='markers', pltname=None):
layout = go.Layout(title = title, yaxis = dict(title = ytitle), xaxis = dict(title = xtitle))
fig = go.Figure(data=traces, layout = layout)
py.offline.iplot(fig)
if __name__ == '__main__':
x = np.linspace(0, np.pi*2, 200)
y = np.sin(x)
trace1 = make_trace(x, y, mode='lines')
trace2 = make_trace(x, y*2, mode='lines')
trace3 = make_trace(x, y/2, mode='lines')
traces = [trace1, trace2, trace3]
plotly_plot(traces)
@limitpointinf0
Copy link
Author

newplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment