This commit is contained in:
Giorgio Calderone 2022-01-03 12:41:12 +01:00
commit 3f40e38d72
2 changed files with 12 additions and 4 deletions

View File

@ -925,7 +925,7 @@ function execall(gp::GPSession; term::AbstractString="", output::AbstractString=
gpexec(gp, "unset multiplot")
gpexec(gp, "set term $term")
end
(output != "") && gpexec(gp, "set output '$output'")
(output != "") && gpexec(gp, "set output '$(replace(output, "'" => "''"))'")
# printstyled("Plotting with terminal: " * terminal() * "\n", color=:blue, bold=true)
@ -1855,16 +1855,20 @@ 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])
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
binsize = x[2] - x[1]
if pad
x = [x[1]-binsize, x..., x[end]+binsize]
h = [0, h..., 0]

View File

@ -286,4 +286,8 @@ Gnuplot.quit(:default)
Gnuplot.options.dry = true
@gp hist(randn(1000))
# Various hist() corner cases
@gp hist([1,2,3], bs=2)
@gp hist([1,1,1], bs=1)
Gnuplot.quitall()