PLOTLY
PLOTLY
In [1]:
import plotly.graph_objs as go
import plotly.express as pex
In [2]:
In [3]:
df =sns.load_dataset('iris')
df.head()
Out[3]:
In [4]:
# line,bar,scatter,histogram,box,scatter_matrix,imshow,pie,violin
In [5]:
fig = pex.line(df['petal_length'],color=df['species'])
fig.show()
7 color
setosa
versico
6 virginic
5
value
index
localhost:8888/notebooks/Plotly.ipynb 1/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [6]:
160 species
setosa
140 versico
virginic
120
100
sepal_length
80
60
40
20
0
2 2.5 3 3.5 4
sepal_width
In [7]:
fig = pex.histogram(df['sepal_width'],color=df['species'])
fig.show()
color
35 setosa
versico
virginic
30
25
count
20
15
10
0
2 2.5 3 3.5 4 4.5
value
localhost:8888/notebooks/Plotly.ipynb 2/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [8]:
fig = pex.scatter(x=df['species'],y=df['sepal_width'],color=df['species'],size=df['petal_length'])
fig.show()
4.5 color
setosa
versico
virginic
4
3.5
y
2.5
In [9]:
fig = pex.pie(values=df['species'].value_counts(),names=df['species'].value_counts().index)
fig.show()
setosa
versico
virginic
33.3% 33.3%
33.3%
localhost:8888/notebooks/Plotly.ipynb 3/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [10]:
fig = pex.box(df.drop(['species'],axis=1),color=df['species'])
fig.show()
8 color
setosa
versico
7
virginic
5
value
0
sepal_length sepal_width petal_length petal_width
variable
In [11]:
fig = pex.violin(df.drop(['species'],axis=1))
fig.show()
6
value
variable
localhost:8888/notebooks/Plotly.ipynb 4/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [12]:
df1 = sns.load_dataset('tips')
df1
Out[12]:
In [13]:
sex
40 Fema
Male
35
30
total_bill
25
20
15
10
1 2 3 4 5 6
tip
size=2
▶ ◼
2 3 4 1 6 5
localhost:8888/notebooks/Plotly.ipynb 5/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [14]:
fig = pex.histogram(df1,x='total_bill',y='tip',histfunc='sum',color='smoker',)
fig.show()
90
smoke
N
Y
80
70
60
sum of tip
50
40
30
20
10
0
10 20 30 40 50
total_bill
In [15]:
fig = pex.scatter_matrix(df,dimensions=['sepal_width','sepal_length','petal_width','petal_length'],color='species')
fig.show()
petal_length petal_width sepal_length sepal_width
4
species
setosa
3 versico
virginic
2
8
7
6
5
4
2 3 4 4 5 6 7 8 0 1 2 2 4 6
localhost:8888/notebooks/Plotly.ipynb 6/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [16]:
fig = pex.scatter(df,x='sepal_width',y='sepal_length',color='species',marginal_x='box',marginal_y='histogram',trendline='ols',template='pl
fig.show()
species
setosa
versico
virginic
7
sepal_length
4
2 2.5 3 3.5 4 4.5
sepal_width
In [17]:
fig = pex.scatter(df,x='sepal_width',y='sepal_length',color='species',marginal_x='box',marginal_y='histogram',trendline='ols',template='pl
fig.show()# trendline='ols'
species
setosa
versico
virginic
7
sepal_length
4
2 2.5 3 3.5 4 4.5
sepal_width
localhost:8888/notebooks/Plotly.ipynb 7/8
12/25/22, 12:47 PM Plotly - Jupyter Notebook
In [18]:
#Heatmap
fig = pex.imshow(df.drop(['species'],axis=1),text_auto=True, aspect="auto")
fig.show()
0 5.1
4.9
4.7
4.6
3.5
3
3.2
3.1
1.4
1.4
1.3
1.5
0.2
0.2
0.2
0.2
20
5.7 3.8 1.7 0.3
40
4.4 3 1.3 0.2
5.1 3.4 1.5 0.2
60
6.6 2.9 4.6 1.3
5 2 3.5 1
6 2.2 4 1
6.7 3 5 1.7
80
6 2.9 4.5 1.5
5 2.3 3.3 1
100
5.1 2.5 3 1.1
5.7 2.5 5 2
120
7.7 2.6 6.9 2.3
6 2.2 5 1.5
140
6 3 4.8 1.8
6.5 3 5.2 2
In [ ]:
localhost:8888/notebooks/Plotly.ipynb 8/8