#!/usr/bin/env python # coding: utf-8 # #### New to Plotly? # Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/). #
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online). #
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started! # #### 3D Line Plot of Brownian Motion # In[1]: import plotly.plotly as py import plotly.graph_objs as go import pandas as pd import numpy as np df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/iris.csv') df.head() def brownian_motion(T = 1, N = 100, mu = 0.1, sigma = 0.01, S0 = 20): dt = float(T)/N t = np.linspace(0, T, N) W = np.random.standard_normal(size = N) W = np.cumsum(W)*np.sqrt(dt) # standard brownian motion X = (mu-0.5*sigma**2)*t + sigma*W S = S0*np.exp(X) # geometric brownian motion return S dates = pd.date_range('2012-01-01', '2013-02-22') T = (dates.max()-dates.min()).days / 365 N = dates.size start_price = 100 y = pd.Series( brownian_motion(T, N, sigma=0.1, S0=start_price), index=dates) z = pd.Series( brownian_motion(T, N, sigma=0.1, S0=start_price), index=dates) trace = go.Scatter3d( x=list(dates), y=y, z=z, marker=dict( size=4, color=z, colorscale='Viridis', ), line=dict( color='#1f77b4', width=1 ) ) data = [trace] layout = dict( width=800, height=700, autosize=False, title='Iris dataset', scene=dict( xaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), yaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), zaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), camera=dict( up=dict( x=0, y=0, z=1 ), eye=dict( x=-1.7428, y=1.0707, z=0.7100, ) ), aspectratio = dict( x=1, y=1, z=0.7 ), aspectmode = 'manual' ), ) fig = dict(data=data, layout=layout) py.iplot(fig, filename='pandas-brownian-motion-3d', height=700) # #### Reference # See https://plotly.com/python/reference/#scatter3d-marker-line for more information and chart attribute options! # In[2]: from IPython.display import display, HTML display(HTML('')) display(HTML('')) get_ipython().system(' pip install git+https://github.com/plotly/publisher.git --upgrade') import publisher publisher.publish( '3d-line.ipynb', 'python/3d-line-plots/', 'Python 3D Line Plots | plotly', 'How to make 3D Line Plots', title= '3D Line Plots in Python | plotly', name = '3D Line Plots', has_thumbnail='true', thumbnail='thumbnail/3d-line.jpg', language='python', display_as='3d_charts', order=3, ipynb= '~notebook_demo/63') # In[ ]: