If I have a pre-fiitted histogram, how would I plot an unfilled histogram with Makie.jl? I can use hist and stephist for the raw data, but I’m not sure what to do about a Histogram object from StatsBase.jl
Example:
using CairoMakie
import StatsBase
sample = randn(5000)
hfit = StatsBase.fit(StatsBase.Histogram, sample)
hist(sample) # plot a filled histogram
stephist(sample) # plot an unfilled histogram
plot(hfit) # plot a filled histogram
barplot(hfit) # plot a filled histogram
hist(hfit) # errors out
stephist(hfit) # errors out
stairs(hfit) # errors out
I’m looking for something in the last section that creates a plot using only hfit.
using CairoMakie
import StatsBase
# Generate sample data
sample = randn(5000)
# Fit the histogram using StatsBase
hfit = StatsBase.fit(StatsBase.Histogram, sample)
# 1. Plot an unfilled step histogram from raw data
# Use 'hist' with a transparent fill and a visible stroke
hist(sample, color = :transparent, strokewidth = 1, strokecolor = :black)
# 2. Plot a filled histogram from a fitted Histogram object
# 'barplot' requires the bin edges (x) and the weights (y)
barplot(hfit.edges[1][1:end-1], hfit.weights)
# 3. Plot a step histogram from a fitted Histogram object
# 'stairs' requires the edges and weights; we append a zero to the weights
# to ensure the array lengths are compatible for the step plot.
stairs(hfit.edges[1], vcat(hfit.weights, 0), step = :post)