You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After trying to find a nice way of creating a 3D-Histogram it turned out that there is no such feature yet. (Although it is reported as possible :seriestype in the Docs/attribute_series)
So I came up with a very hacky way of doing it using wireframe() and I thought the Code may be useful in the future.
functionhistogram3d(x::AbstractArray{T,1}, y::AbstractArray{T,1}; xlims::Tuple{Number,Number}=(0,0), ylims::Tuple{Number,Number}=(0,0), bins::Int64, kws...) where {T}
# input check, if not given take extremaifall(xlims == (0,0))
xlims =extrema(x)
endifall(ylims == (0,0))
ylims =extrema(y)
end# create the x-y-grid to check values
xgrid =range(xlims[1],xlims[end],length=bins+1)
ygrid =range(ylims[1],ylims[end],length=bins+1)
# count all x-y-values within a specific x-y-grid-cell (histcount may be nicer)
z = [sum(all(((x[i],y[i]).>=(xgrid[itx],ygrid[ity])) .& ((x[i],y[i]).<(xgrid[itx+1],ygrid[ity+1]))) for i ineachindex(x)) for ity =1:bins, itx =1:bins]
# Helpers for nice bars
xdat =repeateps(xgrid,inner=(2));
ydat =repeateps(ygrid,inner=(2));
zdat =zeros(length(xdat),length(ydat));
zdat[2:end-1,2:end-1] .=repeat(z,inner=(2,2));
wireframe(xdat,ydat,zdat,xlims=xlims,ylims=ylims;kws...)
endrepeateps(x;kws...) =repeat(x;kws...) .- [k%2==1?1e-15:0for k =1:2*length(x)];
The code basically adds additional points for the wireframe such that the resulting graph contains something that looks like a bar.
However I tried this so far only with the GR- and the plotly-backend.
GR produced quite decent results (apart from the known issue #1911 which makes it hard to look at it from all angles) :
Plotly however completely fails (somehow the vertical parts of the wireframe are missing)
There are probably several other issues with this Code, however it may help someone who knows how to improve this ☺️
Also feel free to delete this post if it is not helpful at all 😉
The text was updated successfully, but these errors were encountered:
We also struggled to find a way to find a 3D histogram and a student has tried two approaches - one as well using wireframe and one using surface to make them more colorful :)
I guess he will post his solution soon
As I said it needs a lot of work still though (;
Especially I found that the repeateps(x,kws...) doesn‘t work always. If the x values are large the hack with an abolute subtraction of 1e-15 is not working. Replaced it in my code now with:
repeateps(x;kws...) =repeat(x;kws...) .- [k%2==1?10*eps(x[Int64((k+1)/2) :0for k =1:2*length(x)];
which is still ugly but works now for arbitrary x-values (;
After trying to find a nice way of creating a 3D-Histogram it turned out that there is no such feature yet. (Although it is reported as possible
:seriestype
in the Docs/attribute_series)So I came up with a very hacky way of doing it using
wireframe()
and I thought the Code may be useful in the future.The code basically adds additional points for the
wireframe
such that the resulting graph contains something that looks like abar
.However I tried this so far only with the GR- and the plotly-backend.
GR produced quite decent results (apart from the known issue #1911 which makes it hard to look at it from all angles) :
Plotly however completely fails (somehow the vertical parts of the wireframe are missing)
There are probably several other issues with this Code, however it may help someone who knows how to improve this☺️
Also feel free to delete this post if it is not helpful at all 😉
The text was updated successfully, but these errors were encountered: