Using Plotly in jupyter notebook

normal static plotting


In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import pandas as pd
from mpl_toolkits.mplot3d.axes3d import Axes3D
%matplotlib notebook

In [2]:
df = pd.read_csv('datasets/iris.csv',index_col=4,header=None,names=['SepalLength', 'SepalWidth', 'PetalLength','PetalWidth'],sep=',')
df.head()
x=df['SepalLength']
y=df['SepalWidth']
z=df['PetalLength']

In [3]:
df1 = df[df.index == 'Iris-setosa']
x1=df1['SepalLength']
y1=df1['SepalWidth']
z1=df1['PetalLength']
df2 = df[df.index == 'Iris-virginica']
x2=df2['SepalLength']
y2=df2['SepalWidth']
z2=df2['PetalLength']
df3 = df[df.index == 'Iris-versicolor']
x3=df3['SepalLength']
y3=df3['SepalWidth']
z3=df3['PetalLength']

In [4]:
#df[df.index == 'Iris-setosa']

In [5]:
#plt.scatter(df['SepalLength'],df['SepalWidth'],df['PetalLength'])
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.scatter(x1,y1,z1,c='b')
ax.scatter(x2,y2,z2,c='r')
ax.scatter(x3,y3,z3,c='g')


Out[5]:
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x7fec38489eb8>

bokeh of the same data set


In [10]:
from bokeh.charts import Scatter, output_file, show
from bokeh.io import output_notebook
from bokeh.plotting import figure
output_notebook()


Loading BokehJS ...

In [7]:
np.unique(df.index)


Out[7]:
array(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica'], dtype=object)

In [17]:
df1 = df[df.index == 'Iris-setosa']
x1=df1['SepalLength']
y1=df1['SepalWidth']
z1=df1['PetalLength']
df2 = df[df.index == 'Iris-virginica']
x2=df2['SepalLength']
y2=df2['SepalWidth']
z2=df2['PetalLength']
df3 = df[df.index == 'Iris-versicolor']
x3=df3['SepalLength']
y3=df3['SepalWidth']
z3=df3['PetalLength']

In [18]:
df.head()


Out[18]:
SepalLength SepalWidth PetalLength PetalWidth
Iris-setosa 5.1 3.5 1.4 0.2
Iris-setosa 4.9 3.0 1.4 0.2
Iris-setosa 4.7 3.2 1.3 0.2
Iris-setosa 4.6 3.1 1.5 0.2
Iris-setosa 5.0 3.6 1.4 0.2

In [20]:
p = Scatter(df1, x='SepalLength', y='SepalWidth', title="HP vs MPG", color="navy",xlabel="Miles Per Gallon", ylabel="Horsepower")
#tools = 'box_zoom,box_select,crosshair,resize,reset,hover'
#p =figure(width=800,height=400,tools=tools)
#p.circle(df1['x1'],df1['y1'],line_width=2)
show(p)



In [ ]: