Introduktion till relationsplot och delplot

Introduktion till datavisualisering med Seaborn

Content Team

DataCamp

Frågor om kvantitativa variabler

Relationsplot

  • Längd vs. vikt

Spridningsdiagram över längd och vikt

Introduktion till datavisualisering med Seaborn

Frågor om kvantitativa variabler

Relationsplot

  • Längd vs. vikt
  • Antal skolfrånvaron vs. slutbetyg

Spridningsdiagram över antal frånvaron och slutbetyg

Introduktion till datavisualisering med Seaborn

Frågor om kvantitativa variabler

Relationsplot

  • Längd vs. vikt
  • Antal skolfrånvaron vs. slutbetyg
  • BNP vs. andel läskunniga

Spridningsdiagram över BNP och andel läskunniga

Introduktion till datavisualisering med Seaborn

Spridningsdiagram med nyans

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Spridningsdiagram med delplot

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Introduktion till relplot()

  • Skapa "relationsplot": spridningsdiagram eller linjediagram

Varför använda relplot() istället för scatterplot()?

  • relplot() låter dig skapa delplot i en enda figur
Introduktion till datavisualisering med Seaborn

scatterplot() vs. relplot()

Med scatterplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="total_bill", 
                y="tip", 
                data=tips)

plt.show()

Med relplot()

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter")

plt.show()
1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Delplot i kolumner

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker")

plt.show()

Spridningsdiagram med rökare-delplot i kolumner

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Delplot i rader

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            row="smoker")

plt.show()

Spridningsdiagram med rökare-delplot i rader

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Delplot i rader och kolumner

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="smoker",
            row="time")

plt.show()

Spridningsdiagram med delplot för rökare och tid

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Undergrupper för veckodagar

Spridningsdiagram med dag-delplot i kolumner

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Radbryt kolumner

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2)

plt.show()

Spridningsdiagram med dag-delplot i kolumner fördelade på två rader

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Sortera kolumner

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips,
            kind="scatter",
            col="day",
            col_wrap=2,
            col_order=["Thur",
                       "Fri",
                       "Sat",
                       "Sun"])

plt.show()

Spridningsdiagram med sorterade dag-delplot

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Introduktion till datavisualisering med Seaborn

Nu kör vi en övning!

Introduktion till datavisualisering med Seaborn

Preparing Video For Download...