|
| 1 | +{ |
| 2 | +"cells": [ |
| 3 | + { |
| 4 | +"cell_type":"code", |
| 5 | +"execution_count":null, |
| 6 | +"metadata": {}, |
| 7 | +"outputs": [], |
| 8 | +"source": [ |
| 9 | +"import plotly.offline as py\n", |
| 10 | +"import plotly.graph_objs as go\n", |
| 11 | +"import plotly.figure_factory as ff\n", |
| 12 | +"import pandas as pd\n", |
| 13 | +"import numpy as np\n", |
| 14 | +"import yfinance as yf\n", |
| 15 | +"import pandas_datareader as pdr\n", |
| 16 | +"\n", |
| 17 | +"py.init_notebook_mode()" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | +"cell_type":"code", |
| 22 | +"execution_count":null, |
| 23 | +"metadata": {}, |
| 24 | +"outputs": [], |
| 25 | +"source": [ |
| 26 | +"x = [ i for i in range(-10,10) ]\n", |
| 27 | +"\n", |
| 28 | +"y = [ i*2 for i in range(-10,10) ]\n", |
| 29 | +"\n", |
| 30 | +"xaxis = go.layout.XAxis(title=\"X Axis\")\n", |
| 31 | +"yaxis = go.layout.YAxis(title=\"Y Axis\")\n", |
| 32 | +"\n", |
| 33 | +"fig = go.Figure(layout=go.Layout(title=\"Simple Line Plot\", xaxis=xaxis, yaxis=yaxis))\n", |
| 34 | +"fig.add_trace(go.Scatter(x=x, y=y))" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | +"cell_type":"code", |
| 39 | +"execution_count":null, |
| 40 | +"metadata": {}, |
| 41 | +"outputs": [], |
| 42 | +"source": [ |
| 43 | +"def sigmoid(x):\n", |
| 44 | +" return 1 / (1 + np.exp((-1) * x))\n", |
| 45 | +"\n", |
| 46 | +"x = sorted(np.random.random(100) * 10 - 5)\n", |
| 47 | +"y = [ sigmoid(i) for i in x ]\n", |
| 48 | +"\n", |
| 49 | +"xaxis = go.layout.XAxis(title=\"X Axis\")\n", |
| 50 | +"yaxis = go.layout.YAxis(title=\"Y Axis\")\n", |
| 51 | +"\n", |
| 52 | +"fig=go.Figure(layout=go.Layout(title=\"Sigmoid Plot\",xaxis=xaxis, yaxis=yaxis))\n", |
| 53 | +"fig.add_trace(go.Scatter(x=x, y=y, marker=dict(color=\"red\")))" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | +"cell_type":"code", |
| 58 | +"execution_count":null, |
| 59 | +"metadata": {}, |
| 60 | +"outputs": [], |
| 61 | +"source": [ |
| 62 | +"l = []\n", |
| 63 | +"\n", |
| 64 | +"for _ in range(5):\n", |
| 65 | +" l.append([ sorted(np.random.randint(low=0, high=10000, size=50)), sorted(np.random.randint(low=0, high=10000, size=50)) ])\n", |
| 66 | +"\n", |
| 67 | +"l = np.array(l)\n", |
| 68 | +"\n", |
| 69 | +"figure = go.Figure(layout=go.Layout(title=\"Simple Scatter Example\", xaxis=go.layout.XAxis(title=\"X\"), yaxis=go.layout.YAxis(title=\"Y\")))\n", |
| 70 | +"for i in range(len(l)):\n", |
| 71 | +" figure.add_trace(go.Scatter(x=l[i][0],y=l[i][1], mode=\"markers\", name=f\" Distribution {i+1}\"))\n", |
| 72 | +"figure.show()" |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | +"cell_type":"code", |
| 77 | +"execution_count":null, |
| 78 | +"metadata": {}, |
| 79 | +"outputs": [], |
| 80 | +"source": [ |
| 81 | +"dist = np.random.normal(loc=0, scale=1, size=50000)" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | +"cell_type":"code", |
| 86 | +"execution_count":null, |
| 87 | +"metadata": {}, |
| 88 | +"outputs": [], |
| 89 | +"source": [ |
| 90 | +"figure = go.Figure()\n", |
| 91 | +"figure.add_trace(go.Histogram(x=dist,))" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | +"cell_type":"code", |
| 96 | +"execution_count":null, |
| 97 | +"metadata": {}, |
| 98 | +"outputs": [], |
| 99 | +"source": [ |
| 100 | +"\n", |
| 101 | +"\n", |
| 102 | +"d=[{\"values\":np.random.normal(0,0.5,10000),\"information\":\" Normal Distribution with mean 0 and std= 0.5\"},\n", |
| 103 | +" {\"values\":np.random.normal(0,1,10000),\"information\":\" Normal Distribution with mean 0 and std= 1\"},\n", |
| 104 | +" {\"values\":np.random.normal(0,1.5,10000),\"information\":\" Normal Distribution with mean 0 and std= 1.5\"},\n", |
| 105 | +" {\"values\":np.random.normal(0,2,10000),\"information\":\" Normal Distribution with mean 0 and std= 2\"},\n", |
| 106 | +" {\"values\":np.random.normal(0,5,10000),\"information\":\" Normal Distribution with mean 0 and std= 5\"}]\n", |
| 107 | +"\n", |
| 108 | +"ff.create_distplot([ele[\"values\"] for ele in d], group_labels=[ele[\"information\"] for ele in d], show_hist=False)" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | +"cell_type":"code", |
| 113 | +"execution_count":null, |
| 114 | +"metadata": {}, |
| 115 | +"outputs": [], |
| 116 | +"source": [ |
| 117 | +"x = np.random.randint(low=5, high=100, size=15)\n", |
| 118 | +"y = np.random.randint(low=5, high=100 ,size=15)\n", |
| 119 | +"z = np.random.randint(low=5, high=100, size=15)\n", |
| 120 | +"\n", |
| 121 | +"fig = go.Figure()\n", |
| 122 | +"fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode=\"markers\"))" |
| 123 | + ] |
| 124 | + }, |
| 125 | + { |
| 126 | +"cell_type":"code", |
| 127 | +"execution_count":null, |
| 128 | +"metadata": {}, |
| 129 | +"outputs": [], |
| 130 | +"source": [ |
| 131 | +"df_iris = pd.read_csv(\"iris.csv\")" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | +"cell_type":"code", |
| 136 | +"execution_count":null, |
| 137 | +"metadata": {}, |
| 138 | +"outputs": [], |
| 139 | +"source": [ |
| 140 | +"fig = go.Figure()\n", |
| 141 | +"species_types = df_iris.species.unique().tolist()\n", |
| 142 | +"\n", |
| 143 | +"for specie in species_types:\n", |
| 144 | +" b = df_iris.species == specie\n", |
| 145 | +" 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\"))\n", |
| 146 | +"\n", |
| 147 | +"\n", |
| 148 | +"fig.show()" |
| 149 | + ] |
| 150 | + }, |
| 151 | + { |
| 152 | +"cell_type":"code", |
| 153 | +"execution_count":null, |
| 154 | +"metadata": {}, |
| 155 | +"outputs": [], |
| 156 | +"source": [ |
| 157 | +"yf.pdr_override()\n", |
| 158 | +"\n", |
| 159 | +"symbols = [\"AAPL\",\"MSFT\"]\n", |
| 160 | +"stocks = []\n", |
| 161 | +"for symbol in symbols:\n", |
| 162 | +" stocks.append(pdr.get_data_yahoo(symbol, start=\"2020-01-01\", end=\"2020-05-31\"))" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | +"cell_type":"code", |
| 167 | +"execution_count":null, |
| 168 | +"metadata": {}, |
| 169 | +"outputs": [], |
| 170 | +"source": [ |
| 171 | +"fig = go.Figure()\n", |
| 172 | +"\n", |
| 173 | +"for stock,symbol in zip(stocks,symbols):\n", |
| 174 | +" fig.add_trace(go.Scatter(x=stock.index, y=stock.Close, name=symbol))\n", |
| 175 | +"\n", |
| 176 | +"fig.show()" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | +"cell_type":"code", |
| 181 | +"execution_count":null, |
| 182 | +"metadata": {}, |
| 183 | +"outputs": [], |
| 184 | +"source": [ |
| 185 | +"df_aapl = pdr.get_data_yahoo(symbol, start=\"2020-01-01\", end=\"2020-05-31\")" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | +"cell_type":"code", |
| 190 | +"execution_count":null, |
| 191 | +"metadata": { |
| 192 | +"scrolled":true |
| 193 | + }, |
| 194 | +"outputs": [], |
| 195 | +"source": [ |
| 196 | +"ff.create_candlestick(dates=df_aapl.index, open=df_aapl.Open, high=df_aapl.High, low=df_aapl.Low, close=df_aapl.Close)" |
| 197 | + ] |
| 198 | + }, |
| 199 | + { |
| 200 | +"cell_type":"code", |
| 201 | +"execution_count":null, |
| 202 | +"metadata": {}, |
| 203 | +"outputs": [], |
| 204 | +"source": [ |
| 205 | +"\n" |
| 206 | + ] |
| 207 | + }, |
| 208 | + { |
| 209 | +"cell_type":"code", |
| 210 | +"execution_count":null, |
| 211 | +"metadata": {}, |
| 212 | +"outputs": [], |
| 213 | +"source": [] |
| 214 | + } |
| 215 | + ], |
| 216 | +"metadata": { |
| 217 | +"kernelspec": { |
| 218 | +"display_name":"Python 3", |
| 219 | +"language":"python", |
| 220 | +"name":"python3" |
| 221 | + }, |
| 222 | +"language_info": { |
| 223 | +"codemirror_mode": { |
| 224 | +"name":"ipython", |
| 225 | +"version":3 |
| 226 | + }, |
| 227 | +"file_extension":".py", |
| 228 | +"mimetype":"text/x-python", |
| 229 | +"name":"python", |
| 230 | +"nbconvert_exporter":"python", |
| 231 | +"pygments_lexer":"ipython3", |
| 232 | +"version":"3.6.6" |
| 233 | + } |
| 234 | + }, |
| 235 | +"nbformat":4, |
| 236 | +"nbformat_minor":4 |
| 237 | +} |