Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inexact error for histogram2d #965

Closed
CorySimon opened this issue Mar 8, 2017 · 4 comments · Fixed by #1237
Closed

Inexact error for histogram2d #965

CorySimon opened this issue Mar 8, 2017 · 4 comments · Fixed by #1237

Comments

@CorySimon
Copy link

Julia, v0.5.1

Works:

myplot = plot(x=rand(10), y=rand(10), Geom.histogram2d,
                       Guide.xlabel("y, true"), Guide.ylabel("y, predicted"))

Throws InexactError().

myplot = plot(x=rand(10), y=ones(10), Geom.histogram2d,
                       Guide.xlabel("y, true"), Guide.ylabel("y, predicted"))

My guess is that the error lies in a place where one bin along a certain axis has all of the values.

ERROR: InexactError()
 in trunc(::Type{Int64}, ::Float64) at ./float.jl:463
 in choose_bin_count_2d(::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Int64, ::Int64, ::Int64) at /Users/csimon/.julia/v0.5/Gadfly/src/bincount.jl:257
 in apply_statistic(::Gadfly.Stat.Histogram2DStatistic, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/csimon/.julia/v0.5/Gadfly/src/statistics.jl:620
 in apply_statistics(::Array{Gadfly.StatisticElement,1}, ::Dict{Symbol,Gadfly.ScaleElement}, ::Gadfly.Coord.Cartesian, ::Gadfly.Aesthetics) at /Users/csimon/.julia/v0.5/Gadfly/src/statistics.jl:38
 in render_prepare(::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Gadfly/src/Gadfly.jl:760
 in render(::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Gadfly/src/Gadfly.jl:819
 in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/html")}, ::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Gadfly/src/Gadfly.jl:1113
 in macro expansion at ./multimedia.jl:143 [inlined]
 in display(::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Gadfly/src/Gadfly.jl:1065
 in hookless(::Media.##7#8{Gadfly.Plot}) at /Users/csimon/.julia/v0.5/Media/src/compat.jl:14
 in render(::Media.NoDisplay, ::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Media/src/compat.jl:27
 in display(::Media.DisplayHook, ::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Media/src/compat.jl:9
 in macro expansion at ./multimedia.jl:143 [inlined]
 in display(::Gadfly.Plot) at /Users/csimon/.julia/v0.5/Gadfly/src/Gadfly.jl:1069
 in print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:154
 in print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:139
 in (::Base.REPL.##22#23{Bool,Base.REPL.##33#42{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:652
 in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at ./LineEdit.jl:1579
 in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in run_frontend(::Base.REPL.LineEditREPL, ::Base.REPL.REPLBackendRef) at ./REPL.jl:903
 in run_repl(::Base.REPL.LineEditREPL, ::Base.##950#951) at ./REPL.jl:188
 in _start() at ./client.jl:363
 in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
@tlnagy
Copy link
Member

tlnagy commented Mar 8, 2017

This is related to #860. It looks like it's being caused by a divide-by-zero operation here:

j = max(1, min(dy, 1 + (@compat floor(Int, (y - y_min) / wy))))
.

It seems as though the bin computation assumes that y_max and y_min are not equal.

@CorySimon
Copy link
Author

@tlnagy Maybe a good default is to set the number of bins to be one in that axis if there is no variance in the data along that axis (min = max) and then choose the bin width to be 1.0? I suppose choosing the bin width is arbitrary and could be misleading, though.

@tlnagy
Copy link
Member

tlnagy commented Mar 8, 2017

Apparently, it isn't quite that simple because it looks like the extents of the y axis isn't being computed properly. So some other modifications will be necessary to get this working.

image

@Mattriks
Copy link
Member

Mattriks commented Mar 9, 2017

A possible workaround:

y=ones(20)
y[1:2] += [-1, 1]*0.1
p = plot(x=rand(20), y=y, Geom.histogram2d(ybincount=1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants