Histogram

Histogram#

Visualize the distribution of a single variable with a histogram.

Goal

Visualize the distribution of indoor temperature for Flat A. A histogram counts how many hours fall into each temperature bin and reveals whether temperatures are symmetric, skewed, or have several peaks (e.g. heating season and summer).

Data Basis

Dataset: flatTempHum.csv — Hourly indoor temperature and humidity measurements.
Column used: FlatA_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

Visualization#

from pyedautils.plots import plot_distribution

fig = plot_distribution(
    df,
    columns=["FlatA_Temp"],
    nbins=50,
    title="Temperature Distribution — Flat A",
    xlab="Temperature [°C]",
)
fig.show()
Customization
  • Adjust the number of bins with nbins to control how fine the histogram is.

  • Pass several columns, e.g. columns=["FlatA_Temp", "FlatB_Temp"], to overlay flats; opacity controls how much they show through.

  • For smooth density curves per season, see Density Plot by Season.