Boxplot#

Compare distributions across multiple groups using interactive boxplots.

Goal

Compare temperature distributions across four flats using interactive Plotly boxplots. Boxplots reveal the median, quartiles, and outliers of each distribution at a glance.

Data Basis

Dataset: flatTempHum.csv — Hourly indoor temperature and humidity measurements from four residential flats (A–D).
Columns used: FlatA_Temp, FlatB_Temp, FlatC_Temp, FlatD_Temp
Time range: October 2018 – September 2020

Data Preparation#

import pandas as pd

url = "https://raw.githubusercontent.com/retomarek/edap/main/edap/sampleData/flatTempHum.csv"
df = pd.read_csv(url, sep=";")
df["time"] = pd.to_datetime(df["time"])
df = df.set_index("time", drop=True)
df.head()
FlatA_Hum FlatA_Temp FlatB_Hum FlatB_Temp FlatC_Hum FlatC_Temp FlatD_Hum FlatD_Temp
time
2018-10-03 00:00:00 53.0 24.43 38.8 22.40 44.0 24.5 49.0 24.43
2018-10-03 01:00:00 53.0 24.40 38.8 22.40 44.0 24.5 49.0 24.40
2018-10-03 02:00:00 53.0 24.40 39.3 22.40 44.7 24.5 48.3 24.38
2018-10-03 03:00:00 53.0 24.40 40.3 22.40 45.0 24.5 48.0 24.33
2018-10-03 04:00:00 53.3 24.40 41.0 22.37 45.2 24.5 47.7 24.30
# Select temperature columns and melt to long format
temp_cols = ["FlatA_Temp", "FlatB_Temp", "FlatC_Temp", "FlatD_Temp"]
df_long = df[temp_cols].melt(var_name="flat", value_name="value")

# Clean up flat names for display
df_long["flat"] = df_long["flat"].str.replace("_Temp", "")
df_long.head()
flat value
0 FlatA 24.43
1 FlatA 24.40
2 FlatA 24.40
3 FlatA 24.40
4 FlatA 24.40

Visualization#

import plotly.express as px

fig = px.box(
    df_long,
    x="flat",
    y="value",
    title="Temperature Distribution by Flat",
    labels={"value": "Temperature [°C]", "flat": "Flat"},
)
fig.show()

Boxplot by Time Group#

Use plot_boxplot() from pyedautils to group values by a time unit (month, hour, weekday, quarter). This reveals seasonal or daily patterns in the data.

from pyedautils.plots import plot_boxplot

fig = plot_boxplot(
    df,
    column="FlatA_Temp",
    groupby="month",
    title="FlatA Temperature by Month",
    ylab="Temperature [°C]",
)
fig.show()
Customization

You can customize the boxplot further:

  • Use color="flat" to assign distinct colors per flat.

  • Set points="all" or points="outliers" to control which data points are shown.

  • Add notched=True to display confidence intervals around the median.

  • Use fig.update_layout(yaxis_title="...") to adjust axis labels.