-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
plotly_viz.py
160 lines (78 loc) · 3.23 KB
/
plotly_viz.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# coding: utf-8
# In[ ]:
import plotly.offline as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import pandas as pd
import numpy as np
import yfinance as yf
import pandas_datareader as pdr
py.init_notebook_mode()
# In[ ]:
x = [ i for i in range(-10,10) ]
y = [ i*2 for i in range(-10,10) ]
xaxis = go.layout.XAxis(title="X Axis")
yaxis = go.layout.YAxis(title="Y Axis")
fig = go.Figure(layout=go.Layout(title="Simple Line Plot", xaxis=xaxis, yaxis=yaxis))
fig.add_trace(go.Scatter(x=x, y=y))
# In[ ]:
def sigmoid(x):
return 1 / (1 + np.exp((-1) * x))
x = sorted(np.random.random(100) * 10 - 5)
y = [ sigmoid(i) for i in x ]
xaxis = go.layout.XAxis(title="X Axis")
yaxis = go.layout.YAxis(title="Y Axis")
fig=go.Figure(layout=go.Layout(title="Sigmoid Plot",xaxis=xaxis, yaxis=yaxis))
fig.add_trace(go.Scatter(x=x, y=y, marker=dict(color="red")))
# In[ ]:
l = []
for _ in range(5):
l.append([ sorted(np.random.randint(low=0, high=10000, size=50)), sorted(np.random.randint(low=0, high=10000, size=50)) ])
l = np.array(l)
figure = go.Figure(layout=go.Layout(title="Simple Scatter Example", xaxis=go.layout.XAxis(title="X"), yaxis=go.layout.YAxis(title="Y")))
for i in range(len(l)):
figure.add_trace(go.Scatter(x=l[i][0],y=l[i][1], mode="markers", name=f" Distribution {i+1} "))
figure.show()
# In[ ]:
dist = np.random.normal(loc=0, scale=1, size=50000)
# In[ ]:
figure = go.Figure()
figure.add_trace(go.Histogram(x=dist,))
# In[ ]:
d=[{"values":np.random.normal(0,0.5,10000), "information": " Normal Distribution with mean 0 and std= 0.5"},
{"values":np.random.normal(0,1,10000), "information": " Normal Distribution with mean 0 and std= 1"},
{"values":np.random.normal(0,1.5,10000), "information": " Normal Distribution with mean 0 and std= 1.5"},
{"values":np.random.normal(0,2,10000), "information": " Normal Distribution with mean 0 and std= 2"},
{"values":np.random.normal(0,5,10000), "information": " Normal Distribution with mean 0 and std= 5"}]
ff.create_distplot([ele["values"] for ele in d], group_labels=[ele["information"] for ele in d], show_hist=False)
# In[ ]:
x = np.random.randint(low=5, high=100, size=15)
y = np.random.randint(low=5, high=100 ,size=15)
z = np.random.randint(low=5, high=100, size=15)
fig = go.Figure()
fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode="markers"))
# In[ ]:
df_iris = pd.read_csv("iris.csv")
# In[ ]:
fig = go.Figure()
species_types = df_iris.species.unique().tolist()
for specie in species_types:
b = df_iris.species == specie
fig.add_trace(go.Scatter3d(x=df_iris["sepal_length"][b], y=df_iris["sepal_width"][b], z=df_iris["petal_width"][b], name=specie, mode="markers"))
fig.show()
# In[ ]:
yf.pdr_override()
symbols = ["AAPL","MSFT"]
stocks = []
for symbol in symbols:
stocks.append(pdr.get_data_yahoo(symbol, start="2020-01-01", end="2020-05-31"))
# In[ ]:
fig = go.Figure()
for stock,symbol in zip(stocks,symbols):
fig.add_trace(go.Scatter(x=stock.index, y=stock.Close, name=symbol))
fig.show()
# In[ ]:
df_aapl = pdr.get_data_yahoo(symbol, start="2020-01-01", end="2020-05-31")
# In[ ]:
ff.create_candlestick(dates=df_aapl.index, open=df_aapl.Open, high=df_aapl.High, low=df_aapl.Low, close=df_aapl.Close)
# In[ ]: