diff --git a/src/Gnuplot.jl b/src/Gnuplot.jl index 7c82e50..a2d8242 100644 --- a/src/Gnuplot.jl +++ b/src/Gnuplot.jl @@ -1846,15 +1846,19 @@ function hist(v::Vector{T}; range=[NaN,NaN], bs=NaN, nbins=0, pad=true) where T if sum(hh.weights) < length(i) j = findall(v[i] .== range[2]) @assert length(j) == (length(i) - sum(hh.weights)) - hh.weights[end] += length(j) + if length(hh.weights) > 0 + hh.weights[end] += length(j) + else + push!(hh.weights, length(j)) + end end else hh = fit(Histogram, v[i], closed=:left) end @assert sum(hh.weights) == length(i) x = collect(hh.edges[1]) - binsize = x[2] - x[1] - x = (x[1:end-1] .+ x[2:end]) ./ 2 + binsize = isfinite(bs) ? bs : x[2] - x[1] + length(x) > 1 && (x = (x[1:end-1] .+ x[2:end]) ./ 2) h = hh.weights if pad x = [x[1]-binsize, x..., x[end]+binsize] diff --git a/test/runtests.jl b/test/runtests.jl index 53fe0fe..a9a806a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -288,5 +288,6 @@ Gnuplot.options.dry = true # Various hist() corner cases @gp hist([1,2,3], bs=2) +@gp hist([1,1,1], bs=1) Gnuplot.quitall()