svgimage-sizes
Image pixel sizes
Are the images a consistent size and shape, or a mix of resolutions and orientations?
How to read it
- Read each dot as one image placed by its width and height in pixels; both axes are logarithmic and share one scale.
- Dashed rays mark common shapes: on the diagonal images are square, below it landscape, above it portrait.
- Clusters of dots show the handful of resolutions in the collection; scattered dots show a mix.
- Callout 1: The 1:1 ray: square images.
- Callout 2: A landscape cluster on the 4:3 ray.
- Callout 3: Portrait images above the diagonal.
Watch out
- Sizes are as stored: a phone photo with a rotation flag can land on the mirrored ray.
- Resizing images to one size for a model hides this spread; check it before you resize.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws what the Python or R engine computed; the chart computes nothing statistical.
- Both axes share one log domain, so equal shapes lie on the same ray and the 1:1 ray is the diagonal; landscape images fall below it, portrait above.
- Sizes are as stored: EXIF orientation is not applied, so a rotated photo can appear on the mirrored ray.
# Image pixel sizes — Codesplash Chart Lab (recipe "image-sizes")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("image-sizes-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["format"] = pd.Categorical(df["format"].astype("string"), categories=["JPEG", "PNG"])
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
W = "width"
H = "height"
G = "format"
RATIOS = {"1:1": 1, "4:3": 4 / 3, "3:2": 3 / 2, "16:9": 16 / 9, "3:4": 3 / 4, "2:3": 2 / 3, "9:16": 9 / 16}
d = df[(df[W] > 0) & (df[H] > 0)]
lo, hi = max(1, min(d[W].min(), d[H].min()) / 1.5), max(d[W].max(), d[H].max()) * 1.5 # one shared log domain
fig, ax = plt.subplots(figsize=(6.5, 6))
for name, r in RATIOS.items():
w0, w1 = max(lo, lo * r), min(hi, hi * r)
if w1 > w0:
ax.plot([w0, w1], [w0 / r, w1 / r], color=REF, linestyle="--", linewidth=0.8, alpha=0.5 if r == 1 else 0.3)
ax.annotate(name, (w1, w1 / r), fontsize=7, ha="right", va="top", color=REF)
groups = levels_of(d[G]) if G else [None]
for i, k in enumerate(groups):
m = (d[G].astype(str) == str(k)) if G else np.ones(len(d), bool)
ax.scatter(d.loc[m, W], d.loc[m, H], s=24, color=PALETTE[i % len(PALETTE)], alpha=0.72, label=k)
ax.set_xscale("log")
ax.set_yscale("log")
ax.set_xlim(lo, hi)
ax.set_ylim(lo, hi)
ax.set_xlabel("width (px)")
ax.set_ylabel("height (px)")
if G:
ax.legend(title=G, fontsize=8)
ax.set_title("Pixel size of each image")
plt.show()Needs pandas, numpy, matplotlib · reads image-sizes-demo.csv · app theme from the optional codesplash helper
# Image pixel sizes — Codesplash Chart Lab (recipe "image-sizes")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("image-sizes-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["format"] = pd.Categorical(df["format"].astype("string"), categories=["JPEG", "PNG"])
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
W = "width"
H = "height"
G = "format"
RATIOS = {"1:1": 1, "4:3": 4 / 3, "3:2": 3 / 2, "16:9": 16 / 9, "3:4": 3 / 4, "2:3": 2 / 3, "9:16": 9 / 16}
d = df[(df[W] > 0) & (df[H] > 0)]
lo, hi = max(1, min(d[W].min(), d[H].min()) / 1.5), max(d[W].max(), d[H].max()) * 1.5
fig = go.Figure()
for name, r in RATIOS.items():
w0, w1 = max(lo, lo * r), min(hi, hi * r)
if w1 > w0:
fig.add_scatter(x=[w0, w1], y=[w0 / r, w1 / r], mode="lines+text", text=["", name], textposition="bottom left",
line=dict(color=REF, dash="dash", width=1), opacity=0.5, showlegend=False)
groups = levels_of(d[G]) if G else [None]
for i, k in enumerate(groups):
m = (d[G].astype(str) == str(k)) if G else np.ones(len(d), bool)
fig.add_scatter(x=d.loc[m, W], y=d.loc[m, H], mode="markers", name=str(k) if k is not None else "images",
marker=dict(size=8, color=PALETTE[i % len(PALETTE)], opacity=0.72))
fig.update_xaxes(type="log", range=[np.log10(lo), np.log10(hi)], title="width (px)")
fig.update_yaxes(type="log", range=[np.log10(lo), np.log10(hi)], title="height (px)", scaleanchor="x")
fig.update_layout(title="Pixel size of each image")
fig.show()Needs pandas, numpy, plotly · reads image-sizes-demo.csv · app theme from the optional codesplash helper
# Image pixel sizes — Codesplash Chart Lab (recipe "image-sizes")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("image-sizes-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["format"]] <- factor(df[["format"]], levels = c("JPEG", "PNG"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
w_col <- "width"
h_col <- "height"
g_col <- "format"
d <- df[df[[w_col]] > 0 & df[[h_col]] > 0, ]
lo <- max(1, min(d[[w_col]], d[[h_col]]) / 1.5); hi <- max(d[[w_col]], d[[h_col]]) * 1.5 # one shared log domain
ratios <- c("1:1" = 1, "4:3" = 4 / 3, "3:2" = 3 / 2, "16:9" = 16 / 9, "3:4" = 3 / 4, "2:3" = 2 / 3, "9:16" = 9 / 16)
rays <- do.call(rbind, lapply(names(ratios), function(n) { r <- ratios[[n]]; w0 <- max(lo, lo * r); w1 <- min(hi, hi * r)
if (w1 > w0) data.frame(name = n, x0 = w0, y0 = w0 / r, x1 = w1, y1 = w1 / r) }))
ks <- if (is.null(g_col)) "images" else levels_of(d[[g_col]])
d$g <- factor(if (is.null(g_col)) "images" else as.character(d[[g_col]]), levels = ks)
p <- ggplot(d, aes(x = .data[[w_col]], y = .data[[h_col]], colour = g)) +
geom_segment(data = rays, aes(x = x0, y = y0, xend = x1, yend = y1), inherit.aes = FALSE, colour = ref_col, linetype = "dashed", alpha = 0.4) +
geom_text(data = rays, aes(x = x1, y = y1, label = name), inherit.aes = FALSE, colour = ref_col, size = 2.6, hjust = 1, vjust = 1.4) +
geom_point(size = 2.2, alpha = 0.72) +
scale_x_log10(limits = c(lo, hi)) + scale_y_log10(limits = c(lo, hi)) + coord_equal() +
scale_colour_manual(values = setNames(rep_len(cs_cat, length(ks)), ks)) +
labs(x = "width (px)", y = "height (px)", colour = g_col, title = "Pixel size of each image") + theme_cs
print(p)Needs ggplot2 · reads image-sizes-demo.csv · app theme from the optional codesplashr helper