import plotly plotly.__version__ import plotly.plotly as py # (New syntax!) tools to communicate with Plotly's server import plotly.tools as tls # (NEW!) useful Python/Plotly tools my_creds = tls.get_credentials_file() # read credentials py.sign_in(my_creds['username'], my_creds['api_key']) # (New syntax!) Plotly sign in import numpy as np def makeGaussian(A, L, fwhm = 3, center=None): """ Make a square gaussian kernel. A is the amplitude of the curve L is the length of a side of the square fwhm is full-width-half-maximum, which can be thought of as an effective radius. """ x = np.arange(0, L, 0.1, float) y = x[:,np.newaxis] if center is None: x0 = y0 = L // 2 else: x0 = center[0] y0 = center[1] return A*np.exp(-4*np.log(2) * ((x-x0)**2 + (y-y0)**2) / fwhm**2) A = 10 # choose a maximum amplitude L = 8 # choose length of square domain # Get coordinate arrays z = makeGaussian(A,L) # Print shape of z z.shape my_surface = dict(z=z, # z coords, a 2D array type='surface', # N.B. 'surface' plot type ) my_fig = dict(data=[my_surface]) # N.B. value link to 'data' must be a list my_fig # print figure dictionary below py.plot(my_fig, validate=False, filename='test-3d') py.iplot(my_fig, validate=False, filename='test-3d') my_scatter3d = dict(x=np.random.rand(50), # x coords y=np.random.rand(50), # y coords z=np.random.rand(50), # z coords type='scatter3d', # N.B. 'scatter3d' plot type ) my_fig = dict(data=[my_scatter3d]) # N.B. value link to 'data' must be a list my_fig py.plot(my_fig, validate=False, filename='test-3d-scatter') py.iplot(my_fig, validate=False, filename='test-3d-scatter') # CSS styling within IPython notebook from IPython.core.display import HTML def css_styling(): styles = open("../../python-user-guide/custom.css", "r").read() return HTML(styles) css_styling()