Replaces min, max, minimum, mean, maximum and extrema with NaNMath versions in places where NaNs can occur. To avoid returning NaN when there are NaNs in the Vector * Also add maximum and minimum * define _-prefaced versions of mean, maximum, minimum, extrema * variable arg numbers for Base methods * Different implementation of the override * remove underscore from 2-arg versions of maximum * some forgotten extrema -> _extrema * Fix bug in _extrema definition * edit comment * replace min and max with _min and _max * Base NaN-compliant functions on NaNMath replace _min and _max with NaNMath versions * Use NaNMath explicitly everywhere * remove unneccesary NaNMath calls * Ensure ceil does not error on NaN * Added one more maximum in gr
This commit is contained in:
parent
84406f0823
commit
d29df4289e
1
REQUIRE
1
REQUIRE
@ -9,3 +9,4 @@ Measures
|
|||||||
Showoff
|
Showoff
|
||||||
StatsBase 0.14.0
|
StatsBase 0.14.0
|
||||||
JSON
|
JSON
|
||||||
|
NaNMath
|
||||||
|
|||||||
@ -10,6 +10,7 @@ using Base.Meta
|
|||||||
@reexport using PlotThemes
|
@reexport using PlotThemes
|
||||||
import Showoff
|
import Showoff
|
||||||
import StatsBase
|
import StatsBase
|
||||||
|
import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563
|
||||||
|
|
||||||
export
|
export
|
||||||
grid,
|
grid,
|
||||||
|
|||||||
22
src/axes.jl
22
src/axes.jl
@ -118,7 +118,7 @@ Base.show(io::IO, axis::Axis) = dumpdict(axis.d, "Axis", true)
|
|||||||
# Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k)
|
# Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k)
|
||||||
Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...)
|
Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...)
|
||||||
Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k)
|
Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k)
|
||||||
Base.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax))
|
NaNMath.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax))
|
||||||
|
|
||||||
|
|
||||||
const _scale_funcs = Dict{Symbol,Function}(
|
const _scale_funcs = Dict{Symbol,Function}(
|
||||||
@ -260,8 +260,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function expand_extrema!(ex::Extrema, v::Number)
|
function expand_extrema!(ex::Extrema, v::Number)
|
||||||
ex.emin = min(v, ex.emin)
|
ex.emin = NaNMath.min(v, ex.emin)
|
||||||
ex.emax = max(v, ex.emax)
|
ex.emax = NaNMath.max(v, ex.emax)
|
||||||
ex
|
ex
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -276,8 +276,8 @@ expand_extrema!(axis::Axis, ::Bool) = axis[:extrema]
|
|||||||
|
|
||||||
function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX})
|
function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX})
|
||||||
ex = axis[:extrema]
|
ex = axis[:extrema]
|
||||||
ex.emin = min(v[1], ex.emin)
|
ex.emin = NaNMath.min(v[1], ex.emin)
|
||||||
ex.emax = max(v[2], ex.emax)
|
ex.emax = NaNMath.max(v[2], ex.emax)
|
||||||
ex
|
ex
|
||||||
end
|
end
|
||||||
function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N})
|
function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N})
|
||||||
@ -349,11 +349,11 @@ function expand_extrema!(sp::Subplot, d::KW)
|
|||||||
|
|
||||||
bw = d[:bar_width]
|
bw = d[:bar_width]
|
||||||
if bw == nothing
|
if bw == nothing
|
||||||
bw = d[:bar_width] = mean(diff(data))
|
bw = d[:bar_width] = NaNMath.mean(diff(data))
|
||||||
end
|
end
|
||||||
axis = sp.attr[Symbol(dsym, :axis)]
|
axis = sp.attr[Symbol(dsym, :axis)]
|
||||||
expand_extrema!(axis, maximum(data) + 0.5maximum(bw))
|
expand_extrema!(axis, NaNMath.maximum(data) + 0.5maximum(bw))
|
||||||
expand_extrema!(axis, minimum(data) - 0.5minimum(bw))
|
expand_extrema!(axis, NaNMath.minimum(data) - 0.5minimum(bw))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -368,8 +368,8 @@ end
|
|||||||
# push the limits out slightly
|
# push the limits out slightly
|
||||||
function widen(lmin, lmax)
|
function widen(lmin, lmax)
|
||||||
span = lmax - lmin
|
span = lmax - lmin
|
||||||
# eps = max(1e-16, min(1e-2span, 1e-10))
|
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10))
|
||||||
eps = max(1e-16, 0.03span)
|
eps = NaNMath.max(1e-16, 0.03span)
|
||||||
lmin-eps, lmax+eps
|
lmin-eps, lmax+eps
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ function discrete_value!(axis::Axis, dv)
|
|||||||
# @show axis[:discrete_map], axis[:discrete_values], dv
|
# @show axis[:discrete_map], axis[:discrete_values], dv
|
||||||
if cv_idx == -1
|
if cv_idx == -1
|
||||||
ex = axis[:extrema]
|
ex = axis[:extrema]
|
||||||
cv = max(0.5, ex.emax + 1.0)
|
cv = NaNMath.max(0.5, ex.emax + 1.0)
|
||||||
expand_extrema!(axis, cv)
|
expand_extrema!(axis, cv)
|
||||||
push!(axis[:discrete_values], dv)
|
push!(axis[:discrete_values], dv)
|
||||||
push!(axis[:continuous_values], cv)
|
push!(axis[:continuous_values], cv)
|
||||||
|
|||||||
@ -304,7 +304,7 @@ function extract_any_color(d, kw_args)
|
|||||||
kw_args[:color_norm] = Vec2f0(clims)
|
kw_args[:color_norm] = Vec2f0(clims)
|
||||||
end
|
end
|
||||||
elseif clims == :auto
|
elseif clims == :auto
|
||||||
kw_args[:color_norm] = Vec2f0(extrema(d[:y]))
|
kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -315,7 +315,7 @@ function extract_any_color(d, kw_args)
|
|||||||
kw_args[:color_norm] = Vec2f0(clims)
|
kw_args[:color_norm] = Vec2f0(clims)
|
||||||
end
|
end
|
||||||
elseif clims == :auto
|
elseif clims == :auto
|
||||||
kw_args[:color_norm] = Vec2f0(extrema(d[:y]))
|
kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y]))
|
||||||
else
|
else
|
||||||
error("Unsupported limits: $clims")
|
error("Unsupported limits: $clims")
|
||||||
end
|
end
|
||||||
@ -367,14 +367,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
dist(a, b) = abs(a-b)
|
dist(a, b) = abs(a-b)
|
||||||
mindist(x, a, b) = min(dist(a, x), dist(b, x))
|
mindist(x, a, b) = NaNMath.min(dist(a, x), dist(b, x))
|
||||||
|
|
||||||
function gappy(x, ps)
|
function gappy(x, ps)
|
||||||
n = length(ps)
|
n = length(ps)
|
||||||
x <= first(ps) && return first(ps) - x
|
x <= first(ps) && return first(ps) - x
|
||||||
for j=1:(n-1)
|
for j=1:(n-1)
|
||||||
p0 = ps[j]
|
p0 = ps[j]
|
||||||
p1 = ps[min(j+1, n)]
|
p1 = ps[NaNMath.min(j+1, n)]
|
||||||
if p0 <= x && p1 >= x
|
if p0 <= x && p1 >= x
|
||||||
return mindist(x, p0, p1) * (isodd(j) ? 1 : -1)
|
return mindist(x, p0, p1) * (isodd(j) ? 1 : -1)
|
||||||
end
|
end
|
||||||
@ -482,7 +482,7 @@ function hover(to_hover, to_display, window)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function extract_extrema(d, kw_args)
|
function extract_extrema(d, kw_args)
|
||||||
xmin, xmax = extrema(d[:x]); ymin, ymax = extrema(d[:y])
|
xmin, xmax = NaNMath.extrema(d[:x]); ymin, ymax = NaNMath.extrema(d[:y])
|
||||||
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin)
|
kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin)
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
@ -509,7 +509,7 @@ function extract_colornorm(d, kw_args)
|
|||||||
else
|
else
|
||||||
d[:y]
|
d[:y]
|
||||||
end
|
end
|
||||||
kw_args[:color_norm] = Vec2f0(extrema(z))
|
kw_args[:color_norm] = Vec2f0(NaNMath.extrema(z))
|
||||||
kw_args[:intensity] = map(Float32, collect(z))
|
kw_args[:intensity] = map(Float32, collect(z))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -781,7 +781,7 @@ function gl_bar(d, kw_args)
|
|||||||
# compute half-width of bars
|
# compute half-width of bars
|
||||||
bw = nothing
|
bw = nothing
|
||||||
hw = if bw == nothing
|
hw = if bw == nothing
|
||||||
mean(diff(x))
|
NaNMath.mean(diff(x))
|
||||||
else
|
else
|
||||||
Float64[cycle(bw,i)*0.5 for i=1:length(x)]
|
Float64[cycle(bw,i)*0.5 for i=1:length(x)]
|
||||||
end
|
end
|
||||||
@ -864,7 +864,7 @@ function gl_boxplot(d, kw_args)
|
|||||||
end
|
end
|
||||||
# change q1 and q5 to show outliers
|
# change q1 and q5 to show outliers
|
||||||
# using maximum and minimum values inside the limits
|
# using maximum and minimum values inside the limits
|
||||||
q1, q5 = extrema(inside)
|
q1, q5 = NaNMath.extrema(inside)
|
||||||
end
|
end
|
||||||
# Box
|
# Box
|
||||||
if notch
|
if notch
|
||||||
@ -1318,7 +1318,7 @@ function gl_contour(x, y, z, kw_args)
|
|||||||
T = eltype(z)
|
T = eltype(z)
|
||||||
levels = Contour.contours(map(T, x), map(T, y), z, h)
|
levels = Contour.contours(map(T, x), map(T, y), z, h)
|
||||||
result = Point2f0[]
|
result = Point2f0[]
|
||||||
zmin, zmax = get(kw_args, :limits, Vec2f0(extrema(z)))
|
zmin, zmax = get(kw_args, :limits, Vec2f0(NaNMath.extrema(z)))
|
||||||
cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1)))
|
cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1)))
|
||||||
colors = RGBA{Float32}[]
|
colors = RGBA{Float32}[]
|
||||||
for c in levels.contours
|
for c in levels.contours
|
||||||
@ -1339,7 +1339,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function gl_heatmap(x,y,z, kw_args)
|
function gl_heatmap(x,y,z, kw_args)
|
||||||
get!(kw_args, :color_norm, Vec2f0(extrema(z)))
|
get!(kw_args, :color_norm, Vec2f0(NaNMath.extrema(z)))
|
||||||
get!(kw_args, :color_map, Plots.make_gradient(cgrad()))
|
get!(kw_args, :color_map, Plots.make_gradient(cgrad()))
|
||||||
delete!(kw_args, :intensity)
|
delete!(kw_args, :intensity)
|
||||||
I = GLVisualize.Intensity{1, Float32}
|
I = GLVisualize.Intensity{1, Float32}
|
||||||
|
|||||||
@ -264,7 +264,7 @@ end
|
|||||||
|
|
||||||
normalize_zvals(zv::Void) = zv
|
normalize_zvals(zv::Void) = zv
|
||||||
function normalize_zvals(zv::AVec)
|
function normalize_zvals(zv::AVec)
|
||||||
vmin, vmax = extrema(zv)
|
vmin, vmax = NaNMath.extrema(zv)
|
||||||
if vmin == vmax
|
if vmin == vmax
|
||||||
zeros(length(zv))
|
zeros(length(zv))
|
||||||
else
|
else
|
||||||
@ -428,7 +428,7 @@ function gr_set_viewport_polar()
|
|||||||
ymax -= 0.05 * (xmax - xmin)
|
ymax -= 0.05 * (xmax - xmin)
|
||||||
xcenter = 0.5 * (xmin + xmax)
|
xcenter = 0.5 * (xmin + xmax)
|
||||||
ycenter = 0.5 * (ymin + ymax)
|
ycenter = 0.5 * (ymin + ymax)
|
||||||
r = 0.5 * min(xmax - xmin, ymax - ymin)
|
r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin)
|
||||||
GR.setviewport(xcenter -r, xcenter + r, ycenter - r, ycenter + r)
|
GR.setviewport(xcenter -r, xcenter + r, ycenter - r, ycenter + r)
|
||||||
GR.setwindow(-1, 1, -1, 1)
|
GR.setwindow(-1, 1, -1, 1)
|
||||||
r
|
r
|
||||||
@ -639,7 +639,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
|
|
||||||
elseif ispolar(sp)
|
elseif ispolar(sp)
|
||||||
r = gr_set_viewport_polar()
|
r = gr_set_viewport_polar()
|
||||||
rmin, rmax = GR.adjustrange(minimum(r), maximum(r))
|
rmin, rmax = GR.adjustrange(NaNMath.minimum(r), NaNMath.maximum(r))
|
||||||
# rmin, rmax = axis_limits(sp[:yaxis])
|
# rmin, rmax = axis_limits(sp[:yaxis])
|
||||||
gr_polaraxes(rmin, rmax)
|
gr_polaraxes(rmin, rmax)
|
||||||
|
|
||||||
@ -824,7 +824,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
# create the colorbar of contour levels
|
# create the colorbar of contour levels
|
||||||
if sp[:colorbar] != :none
|
if sp[:colorbar] != :none
|
||||||
gr_set_viewport_cmap(sp)
|
gr_set_viewport_cmap(sp)
|
||||||
l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255)
|
l = round(Int32, 1000 + (h - NaNMath.minimum(h)) / (NaNMath.maximum(h) - NaNMath.minimum(h)) * 255)
|
||||||
GR.setwindow(xmin, xmax, zmin, zmax)
|
GR.setwindow(xmin, xmax, zmin, zmax)
|
||||||
GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l)
|
GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l)
|
||||||
ztick = 0.5 * GR.tick(zmin, zmax)
|
ztick = 0.5 * GR.tick(zmin, zmax)
|
||||||
|
|||||||
@ -349,7 +349,7 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
|
|||||||
ymin, ymax = axis_limits(yaxis)
|
ymin, ymax = axis_limits(yaxis)
|
||||||
if ispolar(sp)
|
if ispolar(sp)
|
||||||
#Plots.jl appears to give (xmin,xmax) ≜ (Θmin,Θmax) & (ymin,ymax) ≜ (rmin,rmax)
|
#Plots.jl appears to give (xmin,xmax) ≜ (Θmin,Θmax) & (ymin,ymax) ≜ (rmin,rmax)
|
||||||
rmax = max(abs(ymin), abs(ymax))
|
rmax = NaNMath.max(abs(ymin), abs(ymax))
|
||||||
xmin, xmax = -rmax, rmax
|
xmin, xmax = -rmax, rmax
|
||||||
ymin, ymax = -rmax, rmax
|
ymin, ymax = -rmax, rmax
|
||||||
end
|
end
|
||||||
|
|||||||
@ -546,7 +546,7 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
else
|
else
|
||||||
# grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha])
|
# grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha])
|
||||||
grad = as_gradient(series[:markercolor], series[:markeralpha])
|
grad = as_gradient(series[:markercolor], series[:markeralpha])
|
||||||
zmin, zmax = extrema(series[:marker_z])
|
zmin, zmax = NaNMath.extrema(series[:marker_z])
|
||||||
zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line)
|
zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line)
|
||||||
[rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]]
|
[rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -705,11 +705,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# contours on the axis planes
|
# contours on the axis planes
|
||||||
if series[:contours]
|
if series[:contours]
|
||||||
for (zdir,mat) in (("x",x), ("y",y), ("z",z))
|
for (zdir,mat) in (("x",x), ("y",y), ("z",z))
|
||||||
offset = (zdir == "y" ? maximum : minimum)(mat)
|
offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat)
|
||||||
handle = ax[:contourf](x, y, z, levelargs...;
|
handle = ax[:contourf](x, y, z, levelargs...;
|
||||||
zdir = zdir,
|
zdir = zdir,
|
||||||
cmap = py_fillcolormap(series),
|
cmap = py_fillcolormap(series),
|
||||||
offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane
|
offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat) # where to draw the contour plane
|
||||||
)
|
)
|
||||||
push!(handles, handle)
|
push!(handles, handle)
|
||||||
needs_colorbar = true
|
needs_colorbar = true
|
||||||
@ -778,7 +778,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
end
|
end
|
||||||
|
|
||||||
clims = sp[:clims]
|
clims = sp[:clims]
|
||||||
zmin, zmax = extrema(z)
|
zmin, zmax = NaNMath.extrema(z)
|
||||||
extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin
|
extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin
|
||||||
extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax
|
extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax
|
||||||
|
|
||||||
@ -926,14 +926,14 @@ function py_compute_axis_minval(axis::Axis)
|
|||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
v = series.d[axis[:letter]]
|
v = series.d[axis[:letter]]
|
||||||
if !isempty(v)
|
if !isempty(v)
|
||||||
minval = min(minval, minimum(abs(v)))
|
minval = NaNMath.min(minval, NaNMath.minimum(abs(v)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# now if the axis limits go to a smaller abs value, use that instead
|
# now if the axis limits go to a smaller abs value, use that instead
|
||||||
vmin, vmax = axis_limits(axis)
|
vmin, vmax = axis_limits(axis)
|
||||||
minval = min(minval, abs(vmin), abs(vmax))
|
minval = NaNMath.min(minval, abs(vmin), abs(vmax))
|
||||||
|
|
||||||
minval
|
minval
|
||||||
end
|
end
|
||||||
@ -954,7 +954,7 @@ function py_set_scale(ax, axis::Axis)
|
|||||||
elseif scale == :log10
|
elseif scale == :log10
|
||||||
10
|
10
|
||||||
end
|
end
|
||||||
kw[Symbol(:linthresh,letter)] = max(1e-16, py_compute_axis_minval(axis))
|
kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis))
|
||||||
"symlog"
|
"symlog"
|
||||||
end
|
end
|
||||||
func(arg; kw...)
|
func(arg; kw...)
|
||||||
|
|||||||
@ -501,7 +501,7 @@ immutable ZValues
|
|||||||
zrange::Tuple{Float64,Float64}
|
zrange::Tuple{Float64,Float64}
|
||||||
end
|
end
|
||||||
|
|
||||||
function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (minimum(values), maximum(values)))
|
function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (NaNMath.minimum(values), NaNMath.maximum(values)))
|
||||||
ZValues(collect(float(values)), map(Float64, zrange))
|
ZValues(collect(float(values)), map(Float64, zrange))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -645,8 +645,8 @@ function (bc::BezierCurve)(t::Real)
|
|||||||
p
|
p
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.mean(x::Real, y::Real) = 0.5*(x+y)
|
# mean(x::Real, y::Real) = 0.5*(x+y) #commented out as I cannot see this used anywhere and it overwrites a Base method with different functionality
|
||||||
Base.mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps)
|
# mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) # I also could not see this used anywhere, and it's type piracy - implementing a NaNMath version for this would just involve converting to a standard array
|
||||||
|
|
||||||
@deprecate curve_points coords
|
@deprecate curve_points coords
|
||||||
|
|
||||||
@ -659,7 +659,7 @@ function directed_curve(args...; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function extrema_plus_buffer(v, buffmult = 0.2)
|
function extrema_plus_buffer(v, buffmult = 0.2)
|
||||||
vmin,vmax = extrema(v)
|
vmin,vmax = NaNMath.extrema(v)
|
||||||
vdiff = vmax-vmin
|
vdiff = vmax-vmin
|
||||||
buffer = vdiff * buffmult
|
buffer = vdiff * buffmult
|
||||||
vmin - buffer, vmax + buffer
|
vmin - buffer, vmax + buffer
|
||||||
|
|||||||
@ -704,7 +704,7 @@ function link_axes!(axes::Axis...)
|
|||||||
a1 = axes[1]
|
a1 = axes[1]
|
||||||
for i=2:length(axes)
|
for i=2:length(axes)
|
||||||
a2 = axes[i]
|
a2 = axes[i]
|
||||||
expand_extrema!(a1, extrema(a2))
|
expand_extrema!(a1, NaNMath.extrema(a2))
|
||||||
for k in (:extrema, :discrete_values, :continuous_values, :discrete_map)
|
for k in (:extrema, :discrete_values, :continuous_values, :discrete_map)
|
||||||
a2[k] = a1[k]
|
a2[k] = a1[k]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -153,7 +153,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::KW)
|
|||||||
if get(kw, :smooth, false)
|
if get(kw, :smooth, false)
|
||||||
x, y = kw[:x], kw[:y]
|
x, y = kw[:x], kw[:y]
|
||||||
β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y)
|
β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y)
|
||||||
sx = [minimum(x), maximum(x)]
|
sx = [NaNMath.minimum(x), NaNMath.maximum(x)]
|
||||||
sy = β * sx + α
|
sy = β * sx + α
|
||||||
push!(kw_list, merge(copy(kw), KW(
|
push!(kw_list, merge(copy(kw), KW(
|
||||||
:seriestype => :path,
|
:seriestype => :path,
|
||||||
|
|||||||
@ -225,7 +225,7 @@ end
|
|||||||
fr = if yaxis[:scale] == :identity
|
fr = if yaxis[:scale] == :identity
|
||||||
0.0
|
0.0
|
||||||
else
|
else
|
||||||
min(axis_limits(yaxis)[1], minimum(y))
|
NaNMath.min(axis_limits(yaxis)[1], NaNMath.minimum(y))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
newx, newy = zeros(3n), zeros(3n)
|
newx, newy = zeros(3n), zeros(3n)
|
||||||
@ -338,7 +338,7 @@ end
|
|||||||
# compute half-width of bars
|
# compute half-width of bars
|
||||||
bw = d[:bar_width]
|
bw = d[:bar_width]
|
||||||
hw = if bw == nothing
|
hw = if bw == nothing
|
||||||
0.5mean(diff(procx))
|
0.5NaNMath.mean(diff(procx))
|
||||||
else
|
else
|
||||||
Float64[0.5cycle(bw,i) for i=1:length(procx)]
|
Float64[0.5cycle(bw,i) for i=1:length(procx)]
|
||||||
end
|
end
|
||||||
@ -366,7 +366,7 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
# widen limits out a bit
|
# widen limits out a bit
|
||||||
expand_extrema!(axis, widen(extrema(xseg.pts)...))
|
expand_extrema!(axis, widen(NaNMath.extrema(xseg.pts)...))
|
||||||
|
|
||||||
# switch back
|
# switch back
|
||||||
if !isvertical(d)
|
if !isvertical(d)
|
||||||
@ -414,8 +414,8 @@ end
|
|||||||
|
|
||||||
function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol)
|
function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol)
|
||||||
w_adj = _scale_adjusted_values(T, w, wscale)
|
w_adj = _scale_adjusted_values(T, w, wscale)
|
||||||
w_min = minimum(w_adj)
|
w_min = NaNMath.minimum(w_adj)
|
||||||
w_max = maximum(w_adj)
|
w_max = NaNMath.maximum(w_adj)
|
||||||
baseline = _binbarlike_baseline(w_min, wscale)
|
baseline = _binbarlike_baseline(w_min, wscale)
|
||||||
w_adj, baseline
|
w_adj, baseline
|
||||||
end
|
end
|
||||||
@ -548,9 +548,9 @@ Plots.@deps stepbins path
|
|||||||
|
|
||||||
|
|
||||||
function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto)
|
function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto)
|
||||||
_cl(x) = max(ceil(Int, x), 1)
|
_cl(x) = ceil(Int, NaNMath.max(x, one(x)))
|
||||||
_iqr(v) = quantile(v, 0.75) - quantile(v, 0.25)
|
_iqr(v) = quantile(v, 0.75) - quantile(v, 0.25)
|
||||||
_span(v) = maximum(v) - minimum(v)
|
_span(v) = NaNMath.maximum(v) - NaNMath.minimum(v)
|
||||||
|
|
||||||
n_samples = length(linearindices(first(vs)))
|
n_samples = length(linearindices(first(vs)))
|
||||||
# Estimator for number of samples in one row/column of bins along each axis:
|
# Estimator for number of samples in one row/column of bins along each axis:
|
||||||
@ -919,7 +919,7 @@ end
|
|||||||
|
|
||||||
# get the joined vector
|
# get the joined vector
|
||||||
function get_xy(v::AVec{OHLC}, x = 1:length(v))
|
function get_xy(v::AVec{OHLC}, x = 1:length(v))
|
||||||
xdiff = 0.3mean(abs(diff(x)))
|
xdiff = 0.3NaNMath.mean(abs(diff(x)))
|
||||||
x_out, y_out = zeros(0), zeros(0)
|
x_out, y_out = zeros(0), zeros(0)
|
||||||
for (i,ohlc) in enumerate(v)
|
for (i,ohlc) in enumerate(v)
|
||||||
ox,oy = get_xy(ohlc, x[i], xdiff)
|
ox,oy = get_xy(ohlc, x[i], xdiff)
|
||||||
@ -984,8 +984,8 @@ end
|
|||||||
yflip := true
|
yflip := true
|
||||||
aspect_ratio := 1
|
aspect_ratio := 1
|
||||||
rs, cs, zs = findnz(z.surf)
|
rs, cs, zs = findnz(z.surf)
|
||||||
xlim := extrema(cs)
|
xlim := NaNMath.extrema(cs)
|
||||||
ylim := extrema(rs)
|
ylim := NaNMath.extrema(rs)
|
||||||
if d[:markershape] == :none
|
if d[:markershape] == :none
|
||||||
markershape := :circle
|
markershape := :circle
|
||||||
end
|
end
|
||||||
@ -1006,7 +1006,7 @@ end
|
|||||||
|
|
||||||
"Adds a+bx... straight line over the current plot"
|
"Adds a+bx... straight line over the current plot"
|
||||||
function abline!(plt::Plot, a, b; kw...)
|
function abline!(plt::Plot, a, b; kw...)
|
||||||
plot!(plt, [extrema(plt)...], x -> b + a*x; kw...)
|
plot!(plt, [NaNMath.extrema(plt)...], x -> b + a*x; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
abline!(args...; kw...) = abline!(current(), args...; kw...)
|
abline!(args...; kw...) = abline!(current(), args...; kw...)
|
||||||
|
|||||||
28
src/utils.jl
28
src/utils.jl
@ -3,7 +3,7 @@ calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for
|
|||||||
|
|
||||||
"Make histogram-like bins of data"
|
"Make histogram-like bins of data"
|
||||||
function binData(data, nbins)
|
function binData(data, nbins)
|
||||||
lo, hi = extrema(data)
|
lo, hi = NaNMath.extrema(data)
|
||||||
edges = collect(linspace(lo, hi, nbins+1))
|
edges = collect(linspace(lo, hi, nbins+1))
|
||||||
midpoints = calcMidpoints(edges)
|
midpoints = calcMidpoints(edges)
|
||||||
buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data]
|
buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data]
|
||||||
@ -109,7 +109,7 @@ function regressionXY(x, y)
|
|||||||
β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y)
|
β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y)
|
||||||
|
|
||||||
# make a line segment
|
# make a line segment
|
||||||
regx = [minimum(x), maximum(x)]
|
regx = [NaNMath.minimum(x), NaNMath.maximum(x)]
|
||||||
regy = β * regx + α
|
regy = β * regx + α
|
||||||
regx, regy
|
regx, regy
|
||||||
end
|
end
|
||||||
@ -283,9 +283,9 @@ unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[
|
|||||||
# given 2-element lims and a vector of data x, widen lims to account for the extrema of x
|
# given 2-element lims and a vector of data x, widen lims to account for the extrema of x
|
||||||
function _expand_limits(lims, x)
|
function _expand_limits(lims, x)
|
||||||
try
|
try
|
||||||
e1, e2 = extrema(x)
|
e1, e2 = NaNMath.extrema(x)
|
||||||
lims[1] = min(lims[1], e1)
|
lims[1] = NaNMath.min(lims[1], e1)
|
||||||
lims[2] = max(lims[2], e2)
|
lims[2] = NaNMath.max(lims[2], e2)
|
||||||
# catch err
|
# catch err
|
||||||
# warn(err)
|
# warn(err)
|
||||||
end
|
end
|
||||||
@ -334,17 +334,17 @@ sortedkeys(d::Dict) = sort(collect(keys(d)))
|
|||||||
|
|
||||||
"create an (n+1) list of the outsides of heatmap rectangles"
|
"create an (n+1) list of the outsides of heatmap rectangles"
|
||||||
function heatmap_edges(v::AVec)
|
function heatmap_edges(v::AVec)
|
||||||
vmin, vmax = extrema(v)
|
vmin, vmax = NaNMath.extrema(v)
|
||||||
extra = 0.5 * (vmax-vmin) / (length(v)-1)
|
extra = 0.5 * (vmax-vmin) / (length(v)-1)
|
||||||
vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra)
|
vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function calc_r_extrema(x, y)
|
function calc_r_extrema(x, y)
|
||||||
xmin, xmax = extrema(x)
|
xmin, xmax = NaNMath.extrema(x)
|
||||||
ymin, ymax = extrema(y)
|
ymin, ymax = NaNMath.extrema(y)
|
||||||
r = 0.5 * min(xmax - xmin, ymax - ymin)
|
r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin)
|
||||||
extrema(r)
|
NaNMath.extrema(r)
|
||||||
end
|
end
|
||||||
|
|
||||||
function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y))
|
function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y))
|
||||||
@ -645,7 +645,7 @@ end
|
|||||||
# used in updating an existing series
|
# used in updating an existing series
|
||||||
|
|
||||||
extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n)
|
extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n)
|
||||||
extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + maximum(v))
|
extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + NaNMath.maximum(v))
|
||||||
extendSeriesData{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z)
|
extendSeriesData{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z)
|
||||||
extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z)
|
extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z)
|
||||||
extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v)
|
extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v)
|
||||||
@ -871,9 +871,9 @@ mm2px(mm::Real) = float(px / MM_PER_PX)
|
|||||||
|
|
||||||
|
|
||||||
"Smallest x in plot"
|
"Smallest x in plot"
|
||||||
xmin(plt::Plot) = minimum([minimum(series.d[:x]) for series in plt.series_list])
|
xmin(plt::Plot) = NaNMath.minimum([NaNMath.minimum(series.d[:x]) for series in plt.series_list])
|
||||||
"Largest x in plot"
|
"Largest x in plot"
|
||||||
xmax(plt::Plot) = maximum([maximum(series.d[:x]) for series in plt.series_list])
|
xmax(plt::Plot) = NaNMath.maximum([NaNMath.maximum(series.d[:x]) for series in plt.series_list])
|
||||||
|
|
||||||
"Extrema of x-values in plot"
|
"Extrema of x-values in plot"
|
||||||
Base.extrema(plt::Plot) = (xmin(plt), xmax(plt))
|
NaNMath.extrema(plt::Plot) = (xmin(plt), xmax(plt))
|
||||||
|
|||||||
@ -78,12 +78,12 @@ facts("Axes") do
|
|||||||
@fact typeof(axis) --> Plots.Axis
|
@fact typeof(axis) --> Plots.Axis
|
||||||
@fact Plots.discrete_value!(axis, "HI") --> (0.5, 1)
|
@fact Plots.discrete_value!(axis, "HI") --> (0.5, 1)
|
||||||
@fact Plots.discrete_value!(axis, :yo) --> (1.5, 2)
|
@fact Plots.discrete_value!(axis, :yo) --> (1.5, 2)
|
||||||
@fact extrema(axis) --> (0.5,1.5)
|
@fact Plots.NaNMath.extrema(axis) --> (0.5,1.5)
|
||||||
@fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 2, "HI" => 1)
|
@fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 2, "HI" => 1)
|
||||||
|
|
||||||
Plots.discrete_value!(axis, ["x$i" for i=1:5])
|
Plots.discrete_value!(axis, ["x$i" for i=1:5])
|
||||||
Plots.discrete_value!(axis, ["x$i" for i=0:2])
|
Plots.discrete_value!(axis, ["x$i" for i=0:2])
|
||||||
@fact extrema(axis) --> (0.5, 7.5)
|
@fact Plots.NaNMath.extrema(axis) --> (0.5, 7.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user