Skip to content

Histogram2d's default colors with transparent background considered harmful #2053

@yha

Description

@yha

histogram2d renders empty bins as transparent, which contrasts strongly with nearly-empty bins in colormaps where small is dark, including the default colormap:

x = Float64[]
let y = 0.0
    for _=1:500
        push!(x, y += randn() - 0.1y)
    end
end
histogram2d([x[2:end]], [x[1:end-1]])

tmp
I would say this is a misleading representation of the data. This is much better:

histogram2d([x[2:end]], [x[1:end-1]], background="black")

tmp

It's worse when the distribution has spikes surrounded by zeros:

using Distributions
x = let n = 100_000
    rand(Poisson(1),n) .* exp.(rand(n).*(2π*im)) .+ 0.1randn(n)
end
histogram2d(x)

tmp
The spike in the middle is barely visible. The distribution really looks like this:
tmp

I think the best solution is to simply render empty bins as zeros rather than transparent. This is what matplotlib does. The distinction between 0 and 1 should be usually negligible, having to do with noise and sample size.
Alternately, the default colormap for 2d histograms should have white at 0 (I don't think there's currently any such colormap, though some are close), or the default background for it should be black.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions