Skip to content

Commit

Permalink
fix: histogram bugfix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
Evizero committed Aug 21, 2015
1 parent 2276718 commit 466f157
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function safeCeil(num)
end
end

# these are all hacks
magnitude{F<:FloatingPoint}(x::F) = safeRound(-log10(x))
floatround{F<:FloatingPoint,R<:Real}(x::F,m::R) = x > 0 ? round(x, magnitude(m)+1) : -round(-x, magnitude(m)+1)
ceilgnitude{F<:FloatingPoint}(x::F) = safeCeil(-log10(x))
floatround{F<:FloatingPoint,R<:Real}(x::F,m::R) = x==0.?0.: (x > 0 ? round(x, ceilgnitude(m)+1) : -round(-x, ceilgnitude(m)+1))
floatfloor{F<:FloatingPoint,R<:Real}(x::F,m::R) = x > 0 ? floor(x, magnitude(m)) : -ceil(-x, magnitude(m))
floatceil{F<:FloatingPoint,R<:Real}(x::F,m::R) = x > 0 ? ceil(x, magnitude(m)) : -floor(-x, magnitude(m))
floatround{F<:FloatingPoint}(x::F) = x > 0 ? floatround(x,x): floatround(x,-x)
Expand Down
5 changes: 3 additions & 2 deletions src/histogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
function histogram(x, n::Int=5; args...)
edges, counts = hist(x,n)
labels = String[]
binwidth = (edges.step - edges.start) / edges.divisor
binwidth = edges.step / edges.divisor
for i in 1:length(counts)
push!(labels, string("(",edges[i],",",floatround(edges[i]+binwidth),"]"))
val = floatround(edges[i])
push!(labels, string("(",val,",",floatround(val+binwidth),"]"))
end
barplot(labels, counts; symb="", args...)
end
Expand Down

0 comments on commit 466f157

Please sign in to comment.