Check plotly version and sign in using the your username and API key:
import plotly
plotly.__version__
'0.5.13'
py = plotly.plotly("<your-username>", "<your-api-key>")
The following cell has the code used to generate this plot which features a 2d contour histogram (new!), one x histogram, one y histogram and some scatter points.
import numpy as np # we'll need this
# some linear space
t = np.linspace(-1,1.2,2001)
# cubic function plus norm. dist. noise
x = (t**3)+(0.3*np.random.randn(2001))
# sixth power plus norm. dist. noise
y = (t**6)+(0.3*np.random.randn(2001))
# dictionary for the scatter points
scatter = {'x':x,
'y':y,
'mode':'markers',
'name':'points',
'marker':{'color':'rgb(102,0,0)',
'opacity':0.4,'size':2}}
# dictionary for the 2d contour histogram
hist2d = {'x':x,
'y':y,
'type':'histogram2dcontour', # NEw plot type!
'name':'density',
'scl':'Hot', # choose a color scale
'reversescl':True, # reverse to scale
'showscale':False, # don't show the color bar
'ncontours':20} # number of contours
# dictionary for the x histogram
histx = {'x':x,
'type':'histogramx',
'name':'x density',
'yaxis':'y2', # plot on yaxis2
'marker':{'color':'rgb(102,0,0)'}}
# dictionary for th y histogram
histy = {'y':y,
'type':'histogramy',
'name':'y density',
'xaxis':'x2', # plot on xaxis2
'bardir':'h', # horizontal bars!
'marker':{'color':'rgb(102,0,0)'}}
# make data list out of the 4 trace dictionaries
data = [scatter,hist2d,histx,histy]
# some layout options
layout = {'hovermode':'closest', # info about data pt closest to cursor will appear
'width':600,
'height':550,
'autosize':False,
'showlegend':False,
'bargap':0, # no space between bars
'margin':{'t':50},
'xaxis':{'domain':[0,0.85],'showgrid':False,'zeroline':False}, # remove grid
'yaxis':{'domain':[0,0.85],'showgrid':False,'zeroline':False}, # and thick
'xaxis2':{'domain':[0.85,1],'showgrid':False,'zeroline':False}, # zero on
'yaxis2':{'domain':[0.85,1],'showgrid':False,'zeroline':False}} # all axes
# send data to Plotly and embed plot in notebook
py.iplot(data, layout=layout, filename='alex-309')
And now the code used to generate this contour plot.
# select size of square grid
size = 100
# linear space from -2 pi to 2 pi
x = np.linspace(-2*np.pi,2*np.pi,size)
# init. vortex surface
z = np.empty((size,size))
# compute vortex surface
for i,xi in enumerate(x):
r2 = (xi**2+x**2)
z[i] = np.sin(xi)*np.cos(x)*np.sin(r2)/(np.log(r2+1))
# make data list
data = [{'x':x,
'y':x,
'z':z,
'type':'contour'}]
# some layout options
layout = {'width':600,
'height':550,
'margin':{'t':50},
'autosize':False}
# send data to Plotly and embed plot in notebook
py.iplot(data, layout=layout, filename='alex-310')
# CSS styling within IPython notebook
from IPython.core.display import HTML
def css_styling():
styles = open("plotly-python-doc.css", "r").read()
return HTML(styles)
css_styling()