Last active
May 4, 2018 19:02
-
-
Save limitpointinf0/ebcf9ae89c3670155f44170cac140831 to your computer and use it in GitHub Desktop.
Easy Plotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Author
limitpointinf0
commented
May 4, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment