Last active
May 7, 2019 03:16
-
-
Save FabriceMesidor/04fa0ffad1440a067e732c34f83874a1 to your computer and use it in GitHub Desktop.
Codes for graphs
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 | |
from plotly.offline import iplot, init_notebook_mode | |
init_notebook_mode(connected=True) | |
def trace(data, mode = 'markers', name="data"): | |
x_values = list(map(lambda point: point['x'],data)) | |
y_values = list(map(lambda point: point['y'],data)) | |
return {'x': x_values, 'y': y_values, 'mode': mode, 'name': name} | |
def trace_values(x_values, y_values, mode = 'markers', name="data", text_values = []): | |
return {'x': x_values, 'y': y_values, 'mode': mode, 'name': name, 'text': text_values} | |
def layout(x_range = None, y_range = None, options = {}): | |
layout = {} | |
if isinstance(x_range, list): layout.update({'xaxis': {'range': x_range}}) | |
if isinstance(y_range, list): layout.update({'yaxis': {'range': y_range}}) | |
layout.update(options) | |
return layout | |
def plot(traces = [], layout = {}): | |
if not isinstance(traces, list): raise TypeError('first argument must be a list. Instead is', traces) | |
plotly.offline.iplot({'data': traces, 'layout': layout}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment