-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_plotly.py
95 lines (75 loc) · 2 KB
/
7_plotly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# To add a new cell, type '#%%'
# To add a new markdown cell, type '#%% [markdown]'
#%%
from IPython import get_ipython
#%% [markdown]
#<h1> SIT 720 - Python Intro </h1>
#%% [markdown]
# #### Using Plotly for charts
#%%
import sys
get_ipython().system(u'{sys.executable} -m pip install scipy')
#%%
import pandas as pd
df = pd.read_csv(
filepath_or_buffer='https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data',
header=None,
sep=',')
df.columns=['sepal_len', 'sepal_wid', 'petal_len', 'petal_wid', 'class']
df.dropna(how="all", inplace=True) # drops the empty line at file-end
df.tail()
#%%
import plotly as py
import plotly.graph_objects as go
import ipywidgets as widgets
from scipy import special
#%%
#create the data
randomData = np.linspace(0, np.pi, 1000)
#%%
#Create plotly layout
layout = go.layout(
title = "Simple Graph",
yaxis = dict(
title = 'volts'
),
xaxis = dict(
title = 'nanoseconds'
)
)
##Create your graph setup as a trace
trace1 = go.Scatter(
x = randomData,
y = np.sin(randomData),
mode = 'lines',
name = 'Sine(x)',
line = dict(
shape = 'spline'
)
)
##Create your figure
fig = go.Figure(data = [trace1], layout=layout)
fig.show()
#%%
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
# Make figure with subplots
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "bar"},
{"type": "surface"}]])
# Add bar traces to subplot (1, 1)
fig.add_trace(go.Bar(y=[2, 1, 3]), row=1, col=1)
fig.add_trace(go.Bar(y=[3, 2, 1]), row=1, col=1)
fig.add_trace(go.Bar(y=[2.5, 2.5, 3.5]), row=1, col=1)
# Add surface trace to subplot (1, 2)
# Read data from a csv
z_data = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv")
fig.add_surface(z=z_data)
# Hide legend
fig.update_layout(
showlegend=False,
title_text="Default Theme",
height=500,
width=800,
)
fig.show()