Bivariate visualisaties

Introductie tot datavisualisatie met Plotly in Python

Alex Scriven

Data Scientist

Wat zijn bivariate visualisaties?

  • Vergelijking van twee variabelen weergeven

$$

$$

  • Scatterplots
  • Lijngrafieken
  • Correlatieplots
Introductie tot datavisualisatie met Plotly in Python

Scatterplot

  • Een y-as voor één variabele
  • Een x-as voor een andere variabele
  • Elk snijpunt is een punt, bijv. (68, 472)

scatterplot

Introductie tot datavisualisatie met Plotly in Python

Scatterplot met plotly.express

 

import plotly.express as px

fig = px.scatter( data_frame=penguins, x="Body Mass (g)", y="Flipper Length (mm)") fig.show()

Pinguïn-scatter

Introductie tot datavisualisatie met Plotly in Python

Meer plotly.express-argumenten

 

Handige plotly.express-argumenten voor scatterplots:

  • trendline: Voeg verschillende trendlijnen toe
  • symbol: Gebruik verschillende symbolen per categorie

$$

$$

$$

Zie de documentatie voor meer

Introductie tot datavisualisatie met Plotly in Python

Lijngrafieken in plotly.express

  • Laat zien hoe een variabele in de tijd verandert

$$

fig = px.line(
  data_frame=msft_stock,  
  x="Date", 
  y="Open", 
  title="MSFT Stock Price (5Y)")
fig.show()

$$

Eenvoudige lijngrafiek van aandelenkoersen

Introductie tot datavisualisatie met Plotly in Python

Correlatieplot

  • Toont de correlatie tussen meerdere variabelen

$$

De Pearson-correlatiecoëfficiënt:

  • Waarde van -1 tot 1
  • 1 = perfect positief gecorreleerd
  • 0 = geen correlatie
  • -1 = perfect negatief gecorreleerd
Introductie tot datavisualisatie met Plotly in Python

Correlatieplot voorbereiden

 

df bevat gegevens over fietsverhuur en weersomstandigheden

cr = df.corr(method="pearson")
print(cr)

 

Correlatietabel

Introductie tot datavisualisatie met Plotly in Python

Correlatieplot met Plotly

$$

fig = px.imshow(

cr,
text_auto=True,
color_continuous_scale="RdYlGn", zmin=-1, zmax=1)
fig.show()
Introductie tot datavisualisatie met Plotly in Python

Onze correlatieplot

Voorbeeld heatmap

Introductie tot datavisualisatie met Plotly in Python

Laten we oefenen!

Introductie tot datavisualisatie met Plotly in Python

Preparing Video For Download...