Introductie tot lijndiagrammen

Introductie tot datavisualisatie met Seaborn

Content Team

DataCamp

Wat zijn lijndiagrammen?

Twee soorten relationele grafieken: spreidingsdiagrammen en lijndiagrammen

Spreidingsdiagrammen

  • Elk punt is een onafhankelijke observatie

Lijndiagrammen

  • Elk punt is hetzelfde “object”, meestal gevolgd in de tijd

Lijndiagram van aandelenkoers in de tijd

Introductie tot datavisualisatie met Seaborn

Luchtvervuilingsdata

  • Meetstations in de hele stad
  • Luchtmonsters met NO2-niveaus

Eerste vijf rijen van DataFrame luchtvervuiling

Introductie tot datavisualisatie met Seaborn

Spreidingsdiagram

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2_mean", 
            data=air_df_mean, 
            kind="scatter")

plt.show()

Spreidingsdiagram van gemiddelde stikstofdioxide in de tijd

Introductie tot datavisualisatie met Seaborn

Lijndiagram

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2_mean", 
            data=air_df_mean, 
            kind="line")

plt.show()

Lijndiagram van gemiddelde stikstofdioxide in de tijd

Introductie tot datavisualisatie met Seaborn

Subgroepen per locatie

Eerste vijf rijen van DataFrame luchtvervuiling per locatie

Introductie tot datavisualisatie met Seaborn

Subgroepen per locatie

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2_mean", 
            data=air_df_loc_mean, 
            kind="line",
            style="location", 
            hue="location")

plt.show()

Lijndiagram van gemiddelde stikstofdioxide in de tijd per regio

Introductie tot datavisualisatie met Seaborn

Markers toevoegen

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2_mean", 
            data=air_df_loc_mean, 
            kind="line", 
            style="location", 
            hue="location",
            markers=True)

plt.show()

Lijndiagram met markers

Introductie tot datavisualisatie met Seaborn

Lijnstijl uitschakelen

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2_mean", 
            data=air_df_loc_mean, 
            kind="line", 
            style="location", 
            hue="location",
            markers=True,
            dashes=False)

plt.show()

Lijndiagram met markers en doorgetrokken lijnen

Introductie tot datavisualisatie met Seaborn

Meerdere observaties per x-waarde

Eerste vijf rijen van DataFrame luchtvervuiling per station

Introductie tot datavisualisatie met Seaborn

Meerdere observaties per x-waarde

Spreidingsdiagram
import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2", 
            data=air_df, 
            kind="scatter")

plt.show()

Spreidingsdiagram van stikstofdioxide voor alle stations in de tijd

Introductie tot datavisualisatie met Seaborn

Meerdere observaties per x-waarde

Lijndiagram
import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2", 
            data=air_df, 
            kind="line")

plt.show()

Lijndiagram van stikstofdioxide voor alle stations in de tijd

Introductie tot datavisualisatie met Seaborn

Meerdere observaties per x-waarde

De schaduwzone is het betrouwbaarheidsinterval

  • Veronderstelt dat de dataset een aselecte steekproef is
  • 95% zeker dat het gemiddelde binnen dit interval ligt
  • Toont onzekerheid in onze schatting

Lijndiagram van stikstofdioxide voor alle stations in de tijd

Introductie tot datavisualisatie met Seaborn

Betrouwbaarheidsinterval vervangen door standaarddeviatie

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2", 
            data=air_df, 
            kind="line",
            errorbar="sd")

plt.show()

Lijndiagram met standaarddeviatie

Introductie tot datavisualisatie met Seaborn

Betrouwbaarheidsinterval uitschakelen

import matplotlib.pyplot as plt
import seaborn as sns

sns.relplot(x="hour", y="NO_2", 
            data=air_df, 
            kind="line",
            errorbar=None)

plt.show()

Lijndiagram zonder betrouwbaarheidsinterval

Introductie tot datavisualisatie met Seaborn

Laten we oefenen!

Introductie tot datavisualisatie met Seaborn

Preparing Video For Download...