From 3dbe2aa575f40bbf71014a27fdecf4d12b5a3c36 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 22 May 2017 22:49:20 +0200 Subject: [PATCH 01/17] Use NaNMath.extrema rather than Base.extrema To avoid returning NaN when there are NaNs in the Vector --- REQUIRE | 1 + src/Plots.jl | 1 + src/axes.jl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 22f785ac..2f70e7f9 100644 --- a/REQUIRE +++ b/REQUIRE @@ -9,3 +9,4 @@ Measures Showoff StatsBase 0.14.0 JSON +NaNMath diff --git a/src/Plots.jl b/src/Plots.jl index 7e630ad7..19ba90dd 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,6 +10,7 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase +import NaNMath: extrema export grid, diff --git a/src/axes.jl b/src/axes.jl index a5882d9a..8d66278c 100644 --- a/src/axes.jl +++ b/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.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -Base.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) +extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) #This is the NaNMath version, not the Base version const _scale_funcs = Dict{Symbol,Function}( From fc7dd5226b6cc7c2b3ac27013ec9901308b1e87c Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 22 May 2017 23:15:22 +0200 Subject: [PATCH 02/17] Also add maximum and minimum --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 19ba90dd..e1ccbfa6 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,7 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase -import NaNMath: extrema +import NaNMath: extrema, maximum, minimum export grid, From 751447d8a534ae5bfe85827e53349cf389f7f9cb Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:01:31 +0200 Subject: [PATCH 03/17] define _-prefaced versions of mean, maximum, minimum, extrema --- src/Plots.jl | 10 +++++++++- src/axes.jl | 8 ++++---- src/backends.jl | 2 +- src/backends/glvisualize.jl | 22 +++++++++++----------- src/backends/gr.jl | 6 +++--- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 8 ++++---- src/components.jl | 8 ++++---- src/layouts.jl | 18 +++++++++--------- src/pipeline.jl | 2 +- src/recipes.jl | 18 +++++++++--------- src/utils.jl | 26 +++++++++++++------------- test/runtests.jl | 4 ++-- 13 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e1ccbfa6..319a64a2 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,6 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase -import NaNMath: extrema, maximum, minimum export grid, @@ -107,6 +106,15 @@ export # --------------------------------------------------------- +import NaNMath +# define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable +for fun in (:extrema, :minimum, :maximum, :mean) + @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) + @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) +end + +# --------------------------------------------------------- + import Measures import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h const BBox = Measures.Absolute2DBox diff --git a/src/axes.jl b/src/axes.jl index 8d66278c..8722d539 100644 --- a/src/axes.jl +++ b/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.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) #This is the NaNMath version, not the Base version +_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) const _scale_funcs = Dict{Symbol,Function}( @@ -349,11 +349,11 @@ function expand_extrema!(sp::Subplot, d::KW) bw = d[:bar_width] if bw == nothing - bw = d[:bar_width] = mean(diff(data)) + bw = d[:bar_width] = _mean(diff(data)) end axis = sp.attr[Symbol(dsym, :axis)] - expand_extrema!(axis, maximum(data) + 0.5maximum(bw)) - expand_extrema!(axis, minimum(data) - 0.5minimum(bw)) + expand_extrema!(axis, _maximum(data) + 0.5_maximum(bw)) + expand_extrema!(axis, _minimum(data) - 0.5_minimum(bw)) end end diff --git a/src/backends.jl b/src/backends.jl index a402bc5f..72bef57e 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -75,7 +75,7 @@ function tick_padding(axis::Axis) vals, labs = ticks isempty(labs) && return 0mm # ptsz = axis[:tickfont].pointsize * pt - longest_label = maximum(length(lab) for lab in labs) + longest_label = _maximum(length(lab) for lab in labs) # generalize by "rotating" y labels rot = axis[:rotation] + (axis[:letter] == :y ? 90 : 0) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index e97d81fd..cf2c9f1c 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -218,7 +218,7 @@ end function gl_marker(shape::Shape) points = Point2f0[Vec{2,Float32}(p) for p in zip(shape.x, shape.y)] bb = GeometryTypes.AABB(points) - mini, maxi = minimum(bb), maximum(bb) + mini, maxi = _minimum(bb), _maximum(bb) w3 = maxi-mini origin, width = Point2f0(mini[1], mini[2]), Point2f0(w3[1], w3[2]) map!(p -> ((p - origin) ./ width) - 0.5f0, points) # normalize and center @@ -347,7 +347,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(_extrema(d[:y])) end end else @@ -358,7 +358,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(_extrema(d[:y])) else error("Unsupported limits: $clims") end @@ -513,7 +513,7 @@ function hover(to_hover, to_display, window) end GLVisualize._view(robj, popup, camera = cam) bb = GLAbstraction.boundingbox(robj).value - mini = minimum(bb) + mini = _minimum(bb) w = GeometryTypes.widths(bb) wborder = w * 0.08f0 #8 percent border bb = GeometryTypes.AABB{Float32}(mini - wborder, w + 2 * wborder) @@ -525,7 +525,7 @@ function hover(to_hover, to_display, window) end function extract_extrema(d, kw_args) - xmin, xmax = extrema(d[:x]); ymin, ymax = extrema(d[:y]) + xmin, xmax = extrema(d[:x]); ymin, ymax = _extrema(d[:y]) kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) nothing end @@ -552,7 +552,7 @@ function extract_colornorm(d, kw_args) else d[:y] end - kw_args[:color_norm] = Vec2f0(extrema(z)) + kw_args[:color_norm] = Vec2f0(_extrema(z)) kw_args[:intensity] = map(Float32, collect(z)) end end @@ -824,7 +824,7 @@ function gl_bar(d, kw_args) # compute half-width of bars bw = nothing hw = if bw == nothing - mean(diff(x)) + _mean(diff(x)) else Float64[cycle(bw,i)*0.5 for i=1:length(x)] end @@ -907,7 +907,7 @@ function gl_boxplot(d, kw_args) end # change q1 and q5 to show outliers # using maximum and minimum values inside the limits - q1, q5 = extrema(inside) + q1, q5 = _extrema(inside) end # Box if notch @@ -1361,7 +1361,7 @@ function gl_contour(x, y, z, kw_args) T = eltype(z) levels = Contour.contours(map(T, x), map(T, y), z, h) result = Point2f0[] - zmin, zmax = get(kw_args, :limits, Vec2f0(extrema(z))) + zmin, zmax = get(kw_args, :limits, Vec2f0(_extrema(z))) cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1))) colors = RGBA{Float32}[] for c in levels.contours @@ -1382,7 +1382,7 @@ end function gl_heatmap(x,y,z, kw_args) - get!(kw_args, :color_norm, Vec2f0(extrema(z))) + get!(kw_args, :color_norm, Vec2f0(_extrema(z))) get!(kw_args, :color_map, Plots.make_gradient(cgrad())) delete!(kw_args, :intensity) I = GLVisualize.Intensity{1, Float32} @@ -1425,7 +1425,7 @@ function label_scatter(d, w, ho) if isapprox(bbw[3], 0) bbw = Vec3f0(bbw[1], bbw[2], 1) end - mini = minimum(bb) + mini = _minimum(bb) m = GLAbstraction.translationmatrix(-mini) m *= GLAbstraction.scalematrix(1 ./ bbw) kw[:primitive] = m * p diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 5f203c40..fa026559 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -262,7 +262,7 @@ end normalize_zvals(zv::Void) = zv function normalize_zvals(zv::AVec) - vmin, vmax = extrema(zv) + vmin, vmax = _extrema(zv) if vmin == vmax zeros(length(zv)) else @@ -640,7 +640,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif ispolar(sp) r = gr_set_viewport_polar() - rmin, rmax = GR.adjustrange(minimum(r), maximum(r)) + rmin, rmax = GR.adjustrange(_minimum(r), _maximum(r)) # rmin, rmax = axis_limits(sp[:yaxis]) gr_polaraxes(rmin, rmax) @@ -836,7 +836,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # create the colorbar of contour levels if sp[:colorbar] != :none gr_set_viewport_cmap(sp) - l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255) + l = round(Int32, 1000 + (h - _minimum(h)) / (_maximum(h) - _minimum(h)) * 255) GR.setwindow(xmin, xmax, zmin, zmax) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) ztick = 0.5 * GR.tick(zmin, zmax) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 814e4775..2dba181e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -546,7 +546,7 @@ function plotly_series(plt::Plot, series::Series) else # grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha]) grad = as_gradient(series[:markercolor], series[:markeralpha]) - zmin, zmax = extrema(series[:marker_z]) + zmin, zmax = _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) [rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]] end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 69fbe426..579c1401 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -705,11 +705,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # contours on the axis planes if series[:contours] for (zdir,mat) in (("x",x), ("y",y), ("z",z)) - offset = (zdir == "y" ? maximum : minimum)(mat) + offset = (zdir == "y" ? _maximum : _minimum)(mat) handle = ax[:contourf](x, y, z, levelargs...; zdir = zdir, cmap = py_fillcolormap(series), - offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane + offset = (zdir == "y" ? _maximum : _minimum)(mat) # where to draw the contour plane ) push!(handles, handle) needs_colorbar = true @@ -778,7 +778,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end clims = sp[:clims] - zmin, zmax = extrema(z) + zmin, zmax = _extrema(z) extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax @@ -926,7 +926,7 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = min(minval, minimum(abs(v))) + minval = min(minval, _minimum(abs(v))) end end end diff --git a/src/components.jl b/src/components.jl index b20eb3d0..37e0e1c3 100644 --- a/src/components.jl +++ b/src/components.jl @@ -501,7 +501,7 @@ immutable ZValues zrange::Tuple{Float64,Float64} 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} = (_minimum(values), _maximum(values))) ZValues(collect(float(values)), map(Float64, zrange)) end @@ -645,8 +645,8 @@ function (bc::BezierCurve)(t::Real) p end -Base.mean(x::Real, y::Real) = 0.5*(x+y) -Base.mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) +_mean(x::Real, y::Real) = 0.5*(x+y) +_mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) @deprecate curve_points coords @@ -659,7 +659,7 @@ function directed_curve(args...; kw...) end function extrema_plus_buffer(v, buffmult = 0.2) - vmin,vmax = extrema(v) + vmin,vmax = _extrema(v) vdiff = vmax-vmin buffer = vdiff * buffmult vmin - buffer, vmax + buffer diff --git a/src/layouts.jl b/src/layouts.jl index a5814ba1..ff6f955a 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -301,10 +301,10 @@ bottompad(layout::GridLayout) = layout.minpad[4] function _update_min_padding!(layout::GridLayout) map(_update_min_padding!, layout.grid) layout.minpad = ( - maximum(map(leftpad, layout.grid[:,1])), - maximum(map(toppad, layout.grid[1,:])), - maximum(map(rightpad, layout.grid[:,end])), - maximum(map(bottompad, layout.grid[end,:])) + _maximum(map(leftpad, layout.grid[:,1])), + _maximum(map(toppad, layout.grid[1,:])), + _maximum(map(rightpad, layout.grid[:,end])), + _maximum(map(bottompad, layout.grid[end,:])) ) end @@ -349,10 +349,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0 # get the max horizontal (left and right) padding over columns, # and max vertical (bottom and top) padding over rows # TODO: add extra padding here - pad_left = maximum(minpad_left, 1) - pad_top = maximum(minpad_top, 2) - pad_right = maximum(minpad_right, 1) - pad_bottom = maximum(minpad_bottom, 2) + pad_left = _maximum(minpad_left, 1) + pad_top = _maximum(minpad_top, 2) + pad_right = _maximum(minpad_right, 1) + pad_bottom = _maximum(minpad_bottom, 2) # make sure the perimeter match the parent pad_left[1] = max(pad_left[1], minimum_perimeter[1]) @@ -642,7 +642,7 @@ end function create_grid_vcat(expr::Expr) rowsizes = map(rowsize, expr.args) - rmin, rmax = extrema(rowsizes) + rmin, rmax = _extrema(rowsizes) if rmin > 0 && rmin == rmax # we have a grid... build the whole thing # note: rmin is the number of columns diff --git a/src/pipeline.jl b/src/pipeline.jl index 70644055..e385b8a8 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -153,7 +153,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::KW) if get(kw, :smooth, false) x, y = kw[:x], kw[:y] β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) - sx = [minimum(x), maximum(x)] + sx = [_minimum(x), _maximum(x)] sy = β * sx + α push!(kw_list, merge(copy(kw), KW( :seriestype => :path, diff --git a/src/recipes.jl b/src/recipes.jl index 1bc4cad5..4be5018f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - min(axis_limits(yaxis)[1], minimum(y)) + min(axis_limits(yaxis)[1], _minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -338,7 +338,7 @@ end # compute half-width of bars bw = d[:bar_width] hw = if bw == nothing - 0.5mean(diff(procx)) + 0.5_mean(diff(procx)) else Float64[0.5cycle(bw,i) for i=1:length(procx)] end @@ -414,8 +414,8 @@ end function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) w_adj = _scale_adjusted_values(T, w, wscale) - w_min = minimum(w_adj) - w_max = maximum(w_adj) + w_min = _minimum(w_adj) + w_max = _maximum(w_adj) baseline = _binbarlike_baseline(w_min, wscale) w_adj, baseline end @@ -550,7 +550,7 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) _cl(x) = max(ceil(Int, x), 1) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) - _span(v) = maximum(v) - minimum(v) + _span(v) = _maximum(v) - _minimum(v) n_samples = length(linearindices(first(vs))) # Estimator for number of samples in one row/column of bins along each axis: @@ -920,7 +920,7 @@ end # get the joined vector function get_xy(v::AVec{OHLC}, x = 1:length(v)) - xdiff = 0.3mean(abs(diff(x))) + xdiff = 0.3_mean(abs(diff(x))) x_out, y_out = zeros(0), zeros(0) for (i,ohlc) in enumerate(v) ox,oy = get_xy(ohlc, x[i], xdiff) @@ -985,8 +985,8 @@ end yflip := true aspect_ratio := 1 rs, cs, zs = findnz(z.surf) - xlim := extrema(cs) - ylim := extrema(rs) + xlim := _extrema(cs) + ylim := _extrema(rs) if d[:markershape] == :none markershape := :circle end @@ -1007,7 +1007,7 @@ end "Adds a+bx... straight line over the current plot" function abline!(plt::Plot, a, b; kw...) - plot!(plt, [extrema(plt)...], x -> b + a*x; kw...) + plot!(plt, [_extrema(plt)...], x -> b + a*x; kw...) end abline!(args...; kw...) = abline!(current(), args...; kw...) diff --git a/src/utils.jl b/src/utils.jl index da1d1cb6..efdddb45 100644 --- a/src/utils.jl +++ b/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" function binData(data, nbins) - lo, hi = extrema(data) + lo, hi = _extrema(data) edges = collect(linspace(lo, hi, nbins+1)) midpoints = calcMidpoints(edges) 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) # make a line segment - regx = [minimum(x), maximum(x)] + regx = [_minimum(x), _maximum(x)] regy = β * regx + α regx, regy end @@ -187,7 +187,7 @@ type SegmentsIterator end function iter_segments(args...) tup = Plots.wraptuple(args) - n = maximum(map(length, tup)) + n = _maximum(map(length, tup)) SegmentsIterator(tup, n) end @@ -283,7 +283,7 @@ 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 function _expand_limits(lims, x) try - e1, e2 = extrema(x) + e1, e2 = _extrema(x) lims[1] = min(lims[1], e1) lims[2] = max(lims[2], e2) # catch err @@ -334,17 +334,17 @@ sortedkeys(d::Dict) = sort(collect(keys(d))) "create an (n+1) list of the outsides of heatmap rectangles" function heatmap_edges(v::AVec) - vmin, vmax = extrema(v) + vmin, vmax = _extrema(v) extra = 0.5 * (vmax-vmin) / (length(v)-1) vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) end function calc_r_extrema(x, y) - xmin, xmax = extrema(x) - ymin, ymax = extrema(y) + xmin, xmax = _extrema(x) + ymin, ymax = _extrema(y) r = 0.5 * min(xmax - xmin, ymax - ymin) - extrema(r) + _extrema(r) end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) @@ -644,8 +644,8 @@ end # --------------------------------------------------------------- # used in updating an existing series -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::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)) 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::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" -xmin(plt::Plot) = minimum([minimum(series.d[:x]) for series in plt.series_list]) +xmin(plt::Plot) = _minimum([_minimum(series.d[:x]) for series in plt.series_list]) "Largest x in plot" -xmax(plt::Plot) = maximum([maximum(series.d[:x]) for series in plt.series_list]) +xmax(plt::Plot) = _maximum([_maximum(series.d[:x]) for series in plt.series_list]) "Extrema of x-values in plot" -Base.extrema(plt::Plot) = (xmin(plt), xmax(plt)) +_extrema(plt::Plot) = (xmin(plt), xmax(plt)) diff --git a/test/runtests.jl b/test/runtests.jl index 94f95a1b..8434a45f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,12 +78,12 @@ facts("Axes") do @fact typeof(axis) --> Plots.Axis @fact Plots.discrete_value!(axis, "HI") --> (0.5, 1) @fact Plots.discrete_value!(axis, :yo) --> (1.5, 2) - @fact extrema(axis) --> (0.5,1.5) + @fact Plots._extrema(axis) --> (0.5,1.5) @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=0:2]) - @fact extrema(axis) --> (0.5, 7.5) + @fact Plots.extrema(axis) --> (0.5, 7.5) end From dbf9ed6e45dc8d8ef6da662278f1eba4bc4282b6 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:05:21 +0200 Subject: [PATCH 04/17] variable arg numbers for Base methods --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 319a64a2..0f49b301 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -109,7 +109,7 @@ export import NaNMath # define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable for fun in (:extrema, :minimum, :maximum, :mean) - @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) + @eval $(Symbol(string("_",fun)))(x...) = Base.$(fun)(x...) @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) end From bd1d562c571a11a06654b76e8dfe9d6184abf82c Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:51:25 +0200 Subject: [PATCH 05/17] Different implementation of the override --- src/Plots.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 0f49b301..20c41ad1 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -106,11 +106,10 @@ export # --------------------------------------------------------- -import NaNMath # define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable for fun in (:extrema, :minimum, :maximum, :mean) - @eval $(Symbol(string("_",fun)))(x...) = Base.$(fun)(x...) - @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat, N<:Integer}(x::AbstractArray{F, N}) = Base.$(fun)(filter(!isnan(x))) + @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end # --------------------------------------------------------- From 9e32d3743d21cf5dba20e5a70e057ddc5b4d5e96 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:51:46 +0200 Subject: [PATCH 06/17] remove underscore from 2-arg versions of maximum --- src/layouts.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/layouts.jl b/src/layouts.jl index ff6f955a..2e9fd853 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -301,10 +301,10 @@ bottompad(layout::GridLayout) = layout.minpad[4] function _update_min_padding!(layout::GridLayout) map(_update_min_padding!, layout.grid) layout.minpad = ( - _maximum(map(leftpad, layout.grid[:,1])), - _maximum(map(toppad, layout.grid[1,:])), - _maximum(map(rightpad, layout.grid[:,end])), - _maximum(map(bottompad, layout.grid[end,:])) + maximum(map(leftpad, layout.grid[:,1])), + maximum(map(toppad, layout.grid[1,:])), + maximum(map(rightpad, layout.grid[:,end])), + maximum(map(bottompad, layout.grid[end,:])) ) end @@ -349,10 +349,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0 # get the max horizontal (left and right) padding over columns, # and max vertical (bottom and top) padding over rows # TODO: add extra padding here - pad_left = _maximum(minpad_left, 1) - pad_top = _maximum(minpad_top, 2) - pad_right = _maximum(minpad_right, 1) - pad_bottom = _maximum(minpad_bottom, 2) + pad_left = maximum(minpad_left, 1) + pad_top = maximum(minpad_top, 2) + pad_right = maximum(minpad_right, 1) + pad_bottom = maximum(minpad_bottom, 2) # make sure the perimeter match the parent pad_left[1] = max(pad_left[1], minimum_perimeter[1]) From 39e10ffd83552e860b34e3d2ff90b58650f540a8 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 22 May 2017 22:49:20 +0200 Subject: [PATCH 07/17] Use NaNMath.extrema rather than Base.extrema To avoid returning NaN when there are NaNs in the Vector --- REQUIRE | 1 + src/Plots.jl | 1 + src/axes.jl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 22f785ac..2f70e7f9 100644 --- a/REQUIRE +++ b/REQUIRE @@ -9,3 +9,4 @@ Measures Showoff StatsBase 0.14.0 JSON +NaNMath diff --git a/src/Plots.jl b/src/Plots.jl index 7e630ad7..19ba90dd 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,6 +10,7 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase +import NaNMath: extrema export grid, diff --git a/src/axes.jl b/src/axes.jl index a5882d9a..8d66278c 100644 --- a/src/axes.jl +++ b/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.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -Base.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) +extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) #This is the NaNMath version, not the Base version const _scale_funcs = Dict{Symbol,Function}( From 41d63665f0238da69598fce1722bc7d26f953d8c Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 22 May 2017 23:15:22 +0200 Subject: [PATCH 08/17] Also add maximum and minimum --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 19ba90dd..e1ccbfa6 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,7 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase -import NaNMath: extrema +import NaNMath: extrema, maximum, minimum export grid, From 8d21cdec0cfcff248bf3e7141c9e016423a2771f Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:01:31 +0200 Subject: [PATCH 09/17] define _-prefaced versions of mean, maximum, minimum, extrema --- src/Plots.jl | 10 +++++++++- src/axes.jl | 8 ++++---- src/backends.jl | 2 +- src/backends/glvisualize.jl | 22 +++++++++++----------- src/backends/gr.jl | 6 +++--- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 8 ++++---- src/components.jl | 8 ++++---- src/layouts.jl | 18 +++++++++--------- src/pipeline.jl | 2 +- src/recipes.jl | 18 +++++++++--------- src/utils.jl | 26 +++++++++++++------------- test/runtests.jl | 4 ++-- 13 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e1ccbfa6..319a64a2 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,6 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase -import NaNMath: extrema, maximum, minimum export grid, @@ -107,6 +106,15 @@ export # --------------------------------------------------------- +import NaNMath +# define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable +for fun in (:extrema, :minimum, :maximum, :mean) + @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) + @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) +end + +# --------------------------------------------------------- + import Measures import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h const BBox = Measures.Absolute2DBox diff --git a/src/axes.jl b/src/axes.jl index 8d66278c..8722d539 100644 --- a/src/axes.jl +++ b/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.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) #This is the NaNMath version, not the Base version +_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) const _scale_funcs = Dict{Symbol,Function}( @@ -349,11 +349,11 @@ function expand_extrema!(sp::Subplot, d::KW) bw = d[:bar_width] if bw == nothing - bw = d[:bar_width] = mean(diff(data)) + bw = d[:bar_width] = _mean(diff(data)) end axis = sp.attr[Symbol(dsym, :axis)] - expand_extrema!(axis, maximum(data) + 0.5maximum(bw)) - expand_extrema!(axis, minimum(data) - 0.5minimum(bw)) + expand_extrema!(axis, _maximum(data) + 0.5_maximum(bw)) + expand_extrema!(axis, _minimum(data) - 0.5_minimum(bw)) end end diff --git a/src/backends.jl b/src/backends.jl index a402bc5f..72bef57e 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -75,7 +75,7 @@ function tick_padding(axis::Axis) vals, labs = ticks isempty(labs) && return 0mm # ptsz = axis[:tickfont].pointsize * pt - longest_label = maximum(length(lab) for lab in labs) + longest_label = _maximum(length(lab) for lab in labs) # generalize by "rotating" y labels rot = axis[:rotation] + (axis[:letter] == :y ? 90 : 0) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index e97d81fd..cf2c9f1c 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -218,7 +218,7 @@ end function gl_marker(shape::Shape) points = Point2f0[Vec{2,Float32}(p) for p in zip(shape.x, shape.y)] bb = GeometryTypes.AABB(points) - mini, maxi = minimum(bb), maximum(bb) + mini, maxi = _minimum(bb), _maximum(bb) w3 = maxi-mini origin, width = Point2f0(mini[1], mini[2]), Point2f0(w3[1], w3[2]) map!(p -> ((p - origin) ./ width) - 0.5f0, points) # normalize and center @@ -347,7 +347,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(_extrema(d[:y])) end end else @@ -358,7 +358,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(_extrema(d[:y])) else error("Unsupported limits: $clims") end @@ -513,7 +513,7 @@ function hover(to_hover, to_display, window) end GLVisualize._view(robj, popup, camera = cam) bb = GLAbstraction.boundingbox(robj).value - mini = minimum(bb) + mini = _minimum(bb) w = GeometryTypes.widths(bb) wborder = w * 0.08f0 #8 percent border bb = GeometryTypes.AABB{Float32}(mini - wborder, w + 2 * wborder) @@ -525,7 +525,7 @@ function hover(to_hover, to_display, window) end function extract_extrema(d, kw_args) - xmin, xmax = extrema(d[:x]); ymin, ymax = extrema(d[:y]) + xmin, xmax = extrema(d[:x]); ymin, ymax = _extrema(d[:y]) kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) nothing end @@ -552,7 +552,7 @@ function extract_colornorm(d, kw_args) else d[:y] end - kw_args[:color_norm] = Vec2f0(extrema(z)) + kw_args[:color_norm] = Vec2f0(_extrema(z)) kw_args[:intensity] = map(Float32, collect(z)) end end @@ -824,7 +824,7 @@ function gl_bar(d, kw_args) # compute half-width of bars bw = nothing hw = if bw == nothing - mean(diff(x)) + _mean(diff(x)) else Float64[cycle(bw,i)*0.5 for i=1:length(x)] end @@ -907,7 +907,7 @@ function gl_boxplot(d, kw_args) end # change q1 and q5 to show outliers # using maximum and minimum values inside the limits - q1, q5 = extrema(inside) + q1, q5 = _extrema(inside) end # Box if notch @@ -1361,7 +1361,7 @@ function gl_contour(x, y, z, kw_args) T = eltype(z) levels = Contour.contours(map(T, x), map(T, y), z, h) result = Point2f0[] - zmin, zmax = get(kw_args, :limits, Vec2f0(extrema(z))) + zmin, zmax = get(kw_args, :limits, Vec2f0(_extrema(z))) cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1))) colors = RGBA{Float32}[] for c in levels.contours @@ -1382,7 +1382,7 @@ end function gl_heatmap(x,y,z, kw_args) - get!(kw_args, :color_norm, Vec2f0(extrema(z))) + get!(kw_args, :color_norm, Vec2f0(_extrema(z))) get!(kw_args, :color_map, Plots.make_gradient(cgrad())) delete!(kw_args, :intensity) I = GLVisualize.Intensity{1, Float32} @@ -1425,7 +1425,7 @@ function label_scatter(d, w, ho) if isapprox(bbw[3], 0) bbw = Vec3f0(bbw[1], bbw[2], 1) end - mini = minimum(bb) + mini = _minimum(bb) m = GLAbstraction.translationmatrix(-mini) m *= GLAbstraction.scalematrix(1 ./ bbw) kw[:primitive] = m * p diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d2e34390..8fe8082a 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -262,7 +262,7 @@ end normalize_zvals(zv::Void) = zv function normalize_zvals(zv::AVec) - vmin, vmax = extrema(zv) + vmin, vmax = _extrema(zv) if vmin == vmax zeros(length(zv)) else @@ -637,7 +637,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif ispolar(sp) r = gr_set_viewport_polar() - rmin, rmax = GR.adjustrange(minimum(r), maximum(r)) + rmin, rmax = GR.adjustrange(_minimum(r), _maximum(r)) # rmin, rmax = axis_limits(sp[:yaxis]) gr_polaraxes(rmin, rmax) @@ -822,7 +822,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # create the colorbar of contour levels if sp[:colorbar] != :none gr_set_viewport_cmap(sp) - l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255) + l = round(Int32, 1000 + (h - _minimum(h)) / (_maximum(h) - _minimum(h)) * 255) GR.setwindow(xmin, xmax, zmin, zmax) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) ztick = 0.5 * GR.tick(zmin, zmax) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 814e4775..2dba181e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -546,7 +546,7 @@ function plotly_series(plt::Plot, series::Series) else # grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha]) grad = as_gradient(series[:markercolor], series[:markeralpha]) - zmin, zmax = extrema(series[:marker_z]) + zmin, zmax = _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) [rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]] end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 69fbe426..579c1401 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -705,11 +705,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # contours on the axis planes if series[:contours] for (zdir,mat) in (("x",x), ("y",y), ("z",z)) - offset = (zdir == "y" ? maximum : minimum)(mat) + offset = (zdir == "y" ? _maximum : _minimum)(mat) handle = ax[:contourf](x, y, z, levelargs...; zdir = zdir, cmap = py_fillcolormap(series), - offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane + offset = (zdir == "y" ? _maximum : _minimum)(mat) # where to draw the contour plane ) push!(handles, handle) needs_colorbar = true @@ -778,7 +778,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end clims = sp[:clims] - zmin, zmax = extrema(z) + zmin, zmax = _extrema(z) extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax @@ -926,7 +926,7 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = min(minval, minimum(abs(v))) + minval = min(minval, _minimum(abs(v))) end end end diff --git a/src/components.jl b/src/components.jl index b20eb3d0..37e0e1c3 100644 --- a/src/components.jl +++ b/src/components.jl @@ -501,7 +501,7 @@ immutable ZValues zrange::Tuple{Float64,Float64} 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} = (_minimum(values), _maximum(values))) ZValues(collect(float(values)), map(Float64, zrange)) end @@ -645,8 +645,8 @@ function (bc::BezierCurve)(t::Real) p end -Base.mean(x::Real, y::Real) = 0.5*(x+y) -Base.mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) +_mean(x::Real, y::Real) = 0.5*(x+y) +_mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) @deprecate curve_points coords @@ -659,7 +659,7 @@ function directed_curve(args...; kw...) end function extrema_plus_buffer(v, buffmult = 0.2) - vmin,vmax = extrema(v) + vmin,vmax = _extrema(v) vdiff = vmax-vmin buffer = vdiff * buffmult vmin - buffer, vmax + buffer diff --git a/src/layouts.jl b/src/layouts.jl index a5814ba1..ff6f955a 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -301,10 +301,10 @@ bottompad(layout::GridLayout) = layout.minpad[4] function _update_min_padding!(layout::GridLayout) map(_update_min_padding!, layout.grid) layout.minpad = ( - maximum(map(leftpad, layout.grid[:,1])), - maximum(map(toppad, layout.grid[1,:])), - maximum(map(rightpad, layout.grid[:,end])), - maximum(map(bottompad, layout.grid[end,:])) + _maximum(map(leftpad, layout.grid[:,1])), + _maximum(map(toppad, layout.grid[1,:])), + _maximum(map(rightpad, layout.grid[:,end])), + _maximum(map(bottompad, layout.grid[end,:])) ) end @@ -349,10 +349,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0 # get the max horizontal (left and right) padding over columns, # and max vertical (bottom and top) padding over rows # TODO: add extra padding here - pad_left = maximum(minpad_left, 1) - pad_top = maximum(minpad_top, 2) - pad_right = maximum(minpad_right, 1) - pad_bottom = maximum(minpad_bottom, 2) + pad_left = _maximum(minpad_left, 1) + pad_top = _maximum(minpad_top, 2) + pad_right = _maximum(minpad_right, 1) + pad_bottom = _maximum(minpad_bottom, 2) # make sure the perimeter match the parent pad_left[1] = max(pad_left[1], minimum_perimeter[1]) @@ -642,7 +642,7 @@ end function create_grid_vcat(expr::Expr) rowsizes = map(rowsize, expr.args) - rmin, rmax = extrema(rowsizes) + rmin, rmax = _extrema(rowsizes) if rmin > 0 && rmin == rmax # we have a grid... build the whole thing # note: rmin is the number of columns diff --git a/src/pipeline.jl b/src/pipeline.jl index 70644055..e385b8a8 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -153,7 +153,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::KW) if get(kw, :smooth, false) x, y = kw[:x], kw[:y] β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) - sx = [minimum(x), maximum(x)] + sx = [_minimum(x), _maximum(x)] sy = β * sx + α push!(kw_list, merge(copy(kw), KW( :seriestype => :path, diff --git a/src/recipes.jl b/src/recipes.jl index 1bc4cad5..4be5018f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - min(axis_limits(yaxis)[1], minimum(y)) + min(axis_limits(yaxis)[1], _minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -338,7 +338,7 @@ end # compute half-width of bars bw = d[:bar_width] hw = if bw == nothing - 0.5mean(diff(procx)) + 0.5_mean(diff(procx)) else Float64[0.5cycle(bw,i) for i=1:length(procx)] end @@ -414,8 +414,8 @@ end function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) w_adj = _scale_adjusted_values(T, w, wscale) - w_min = minimum(w_adj) - w_max = maximum(w_adj) + w_min = _minimum(w_adj) + w_max = _maximum(w_adj) baseline = _binbarlike_baseline(w_min, wscale) w_adj, baseline end @@ -550,7 +550,7 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) _cl(x) = max(ceil(Int, x), 1) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) - _span(v) = maximum(v) - minimum(v) + _span(v) = _maximum(v) - _minimum(v) n_samples = length(linearindices(first(vs))) # Estimator for number of samples in one row/column of bins along each axis: @@ -920,7 +920,7 @@ end # get the joined vector function get_xy(v::AVec{OHLC}, x = 1:length(v)) - xdiff = 0.3mean(abs(diff(x))) + xdiff = 0.3_mean(abs(diff(x))) x_out, y_out = zeros(0), zeros(0) for (i,ohlc) in enumerate(v) ox,oy = get_xy(ohlc, x[i], xdiff) @@ -985,8 +985,8 @@ end yflip := true aspect_ratio := 1 rs, cs, zs = findnz(z.surf) - xlim := extrema(cs) - ylim := extrema(rs) + xlim := _extrema(cs) + ylim := _extrema(rs) if d[:markershape] == :none markershape := :circle end @@ -1007,7 +1007,7 @@ end "Adds a+bx... straight line over the current plot" function abline!(plt::Plot, a, b; kw...) - plot!(plt, [extrema(plt)...], x -> b + a*x; kw...) + plot!(plt, [_extrema(plt)...], x -> b + a*x; kw...) end abline!(args...; kw...) = abline!(current(), args...; kw...) diff --git a/src/utils.jl b/src/utils.jl index da1d1cb6..efdddb45 100644 --- a/src/utils.jl +++ b/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" function binData(data, nbins) - lo, hi = extrema(data) + lo, hi = _extrema(data) edges = collect(linspace(lo, hi, nbins+1)) midpoints = calcMidpoints(edges) 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) # make a line segment - regx = [minimum(x), maximum(x)] + regx = [_minimum(x), _maximum(x)] regy = β * regx + α regx, regy end @@ -187,7 +187,7 @@ type SegmentsIterator end function iter_segments(args...) tup = Plots.wraptuple(args) - n = maximum(map(length, tup)) + n = _maximum(map(length, tup)) SegmentsIterator(tup, n) end @@ -283,7 +283,7 @@ 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 function _expand_limits(lims, x) try - e1, e2 = extrema(x) + e1, e2 = _extrema(x) lims[1] = min(lims[1], e1) lims[2] = max(lims[2], e2) # catch err @@ -334,17 +334,17 @@ sortedkeys(d::Dict) = sort(collect(keys(d))) "create an (n+1) list of the outsides of heatmap rectangles" function heatmap_edges(v::AVec) - vmin, vmax = extrema(v) + vmin, vmax = _extrema(v) extra = 0.5 * (vmax-vmin) / (length(v)-1) vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) end function calc_r_extrema(x, y) - xmin, xmax = extrema(x) - ymin, ymax = extrema(y) + xmin, xmax = _extrema(x) + ymin, ymax = _extrema(y) r = 0.5 * min(xmax - xmin, ymax - ymin) - extrema(r) + _extrema(r) end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) @@ -644,8 +644,8 @@ end # --------------------------------------------------------------- # used in updating an existing series -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::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)) 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::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" -xmin(plt::Plot) = minimum([minimum(series.d[:x]) for series in plt.series_list]) +xmin(plt::Plot) = _minimum([_minimum(series.d[:x]) for series in plt.series_list]) "Largest x in plot" -xmax(plt::Plot) = maximum([maximum(series.d[:x]) for series in plt.series_list]) +xmax(plt::Plot) = _maximum([_maximum(series.d[:x]) for series in plt.series_list]) "Extrema of x-values in plot" -Base.extrema(plt::Plot) = (xmin(plt), xmax(plt)) +_extrema(plt::Plot) = (xmin(plt), xmax(plt)) diff --git a/test/runtests.jl b/test/runtests.jl index 94f95a1b..8434a45f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -78,12 +78,12 @@ facts("Axes") do @fact typeof(axis) --> Plots.Axis @fact Plots.discrete_value!(axis, "HI") --> (0.5, 1) @fact Plots.discrete_value!(axis, :yo) --> (1.5, 2) - @fact extrema(axis) --> (0.5,1.5) + @fact Plots._extrema(axis) --> (0.5,1.5) @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=0:2]) - @fact extrema(axis) --> (0.5, 7.5) + @fact Plots.extrema(axis) --> (0.5, 7.5) end From 132b5176fe37a9744a3a44f603df94445d2d81aa Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:05:21 +0200 Subject: [PATCH 10/17] variable arg numbers for Base methods --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 319a64a2..0f49b301 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -109,7 +109,7 @@ export import NaNMath # define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable for fun in (:extrema, :minimum, :maximum, :mean) - @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) + @eval $(Symbol(string("_",fun)))(x...) = Base.$(fun)(x...) @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) end From 1107f86bd8655d252d0c2a2679be93e19c6b2024 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:51:25 +0200 Subject: [PATCH 11/17] Different implementation of the override --- src/Plots.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 0f49b301..20c41ad1 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -106,11 +106,10 @@ export # --------------------------------------------------------- -import NaNMath # define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable for fun in (:extrema, :minimum, :maximum, :mean) - @eval $(Symbol(string("_",fun)))(x...) = Base.$(fun)(x...) - @eval $(Symbol(string("_",fun))){F <: AbstractFloat}(x::AbstractVector{F}) = NaNMath.$(fun)(x) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat, N<:Integer}(x::AbstractArray{F, N}) = Base.$(fun)(filter(!isnan(x))) + @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end # --------------------------------------------------------- From 804d6ed182457cd1d03689eb001fea69ef61d2e5 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 25 May 2017 12:51:46 +0200 Subject: [PATCH 12/17] remove underscore from 2-arg versions of maximum --- src/layouts.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/layouts.jl b/src/layouts.jl index ff6f955a..2e9fd853 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -301,10 +301,10 @@ bottompad(layout::GridLayout) = layout.minpad[4] function _update_min_padding!(layout::GridLayout) map(_update_min_padding!, layout.grid) layout.minpad = ( - _maximum(map(leftpad, layout.grid[:,1])), - _maximum(map(toppad, layout.grid[1,:])), - _maximum(map(rightpad, layout.grid[:,end])), - _maximum(map(bottompad, layout.grid[end,:])) + maximum(map(leftpad, layout.grid[:,1])), + maximum(map(toppad, layout.grid[1,:])), + maximum(map(rightpad, layout.grid[:,end])), + maximum(map(bottompad, layout.grid[end,:])) ) end @@ -349,10 +349,10 @@ function update_child_bboxes!(layout::GridLayout, minimum_perimeter = [0mm,0mm,0 # get the max horizontal (left and right) padding over columns, # and max vertical (bottom and top) padding over rows # TODO: add extra padding here - pad_left = _maximum(minpad_left, 1) - pad_top = _maximum(minpad_top, 2) - pad_right = _maximum(minpad_right, 1) - pad_bottom = _maximum(minpad_bottom, 2) + pad_left = maximum(minpad_left, 1) + pad_top = maximum(minpad_top, 2) + pad_right = maximum(minpad_right, 1) + pad_bottom = maximum(minpad_bottom, 2) # make sure the perimeter match the parent pad_left[1] = max(pad_left[1], minimum_perimeter[1]) From 392ced81c920d3edf3b9c439af920be265606f67 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 30 May 2017 16:55:30 +0200 Subject: [PATCH 13/17] some forgotten extrema -> _extrema --- src/backends/glvisualize.jl | 2 +- src/layouts.jl | 2 +- src/recipes.jl | 2 +- test/runtests.jl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index cf2c9f1c..cc75917f 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -525,7 +525,7 @@ function hover(to_hover, to_display, window) end function extract_extrema(d, kw_args) - xmin, xmax = extrema(d[:x]); ymin, ymax = _extrema(d[:y]) + xmin, xmax = _extrema(d[:x]); ymin, ymax = _extrema(d[:y]) kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) nothing end diff --git a/src/layouts.jl b/src/layouts.jl index 2e9fd853..9b123839 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -704,7 +704,7 @@ function link_axes!(axes::Axis...) a1 = axes[1] for i=2:length(axes) a2 = axes[i] - expand_extrema!(a1, extrema(a2)) + expand_extrema!(a1, _extrema(a2)) for k in (:extrema, :discrete_values, :continuous_values, :discrete_map) a2[k] = a1[k] end diff --git a/src/recipes.jl b/src/recipes.jl index 4be5018f..e575b645 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -366,7 +366,7 @@ end end # widen limits out a bit - expand_extrema!(axis, widen(extrema(xseg.pts)...)) + expand_extrema!(axis, widen(_extrema(xseg.pts)...)) # switch back if !isvertical(d) diff --git a/test/runtests.jl b/test/runtests.jl index 8434a45f..6e4d3f98 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -83,7 +83,7 @@ facts("Axes") do Plots.discrete_value!(axis, ["x$i" for i=1:5]) Plots.discrete_value!(axis, ["x$i" for i=0:2]) - @fact Plots.extrema(axis) --> (0.5, 7.5) + @fact Plots._extrema(axis) --> (0.5, 7.5) end From c30a2bb9e02752785a5a960f7270f36883ac4e66 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 30 May 2017 16:55:50 +0200 Subject: [PATCH 14/17] Fix bug in _extrema definition --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 20c41ad1..68c0308f 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -108,7 +108,7 @@ export # define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable for fun in (:extrema, :minimum, :maximum, :mean) - @eval $(Symbol(string("_",fun))){F<:AbstractFloat, N<:Integer}(x::AbstractArray{F, N}) = Base.$(fun)(filter(!isnan(x))) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = Base.$(fun)(filter(!isnan,x)) @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end From 172805bcf9c5b12d029470fa52164d631c834604 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 30 May 2017 21:19:16 +0200 Subject: [PATCH 15/17] edit comment --- src/Plots.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 68c0308f..d17af86a 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -106,8 +106,8 @@ export # --------------------------------------------------------- -# define functions (e.g. `_extrema`, that uses the NaNMath version (which ignores NaNs)) when the type is applicable -for fun in (:extrema, :minimum, :maximum, :mean) +# define functions (e.g. `_extrema`, that ignores NaNs, when the type is applicable. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 +for fun in (:extrema, :minimum, :maximum) @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = Base.$(fun)(filter(!isnan,x)) @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end From 74ad9fb880270cf4681d217a8efd392ea3717e63 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 30 May 2017 21:58:04 +0200 Subject: [PATCH 16/17] replace min and max with _min and _max --- src/axes.jl | 14 +++++++------- src/backends/glvisualize.jl | 4 ++-- src/backends/gr.jl | 6 +++--- src/backends/inspectdr.jl | 2 +- src/backends/pyplot.jl | 14 +++++++------- src/layouts.jl | 8 ++++---- src/recipes.jl | 4 ++-- src/utils.jl | 8 ++++---- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 8722d539..54fe0c6d 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -260,8 +260,8 @@ end function expand_extrema!(ex::Extrema, v::Number) - ex.emin = min(v, ex.emin) - ex.emax = max(v, ex.emax) + ex.emin = _min(v, ex.emin) + ex.emax = _max(v, ex.emax) ex 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}) ex = axis[:extrema] - ex.emin = min(v[1], ex.emin) - ex.emax = max(v[2], ex.emax) + ex.emin = _min(v[1], ex.emin) + ex.emax = _max(v[2], ex.emax) ex end function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N}) @@ -368,8 +368,8 @@ end # push the limits out slightly function widen(lmin, lmax) span = lmax - lmin - # eps = max(1e-16, min(1e-2span, 1e-10)) - eps = max(1e-16, 0.03span) + # eps = _max(1e-16, min(1e-2span, 1e-10)) + eps = _max(1e-16, 0.03span) lmin-eps, lmax+eps end @@ -425,7 +425,7 @@ function discrete_value!(axis::Axis, dv) # @show axis[:discrete_map], axis[:discrete_values], dv if cv_idx == -1 ex = axis[:extrema] - cv = max(0.5, ex.emax + 1.0) + cv = _max(0.5, ex.emax + 1.0) expand_extrema!(axis, cv) push!(axis[:discrete_values], dv) push!(axis[:continuous_values], cv) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index cc75917f..b1fb4ac4 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -410,14 +410,14 @@ end dist(a, b) = abs(a-b) -mindist(x, a, b) = min(dist(a, x), dist(b, x)) +mindist(x, a, b) = _min(dist(a, x), dist(b, x)) function gappy(x, ps) n = length(ps) x <= first(ps) && return first(ps) - x for j=1:(n-1) p0 = ps[j] - p1 = ps[min(j+1, n)] + p1 = ps[_min(j+1, n)] if p0 <= x && p1 >= x return mindist(x, p0, p1) * (isodd(j) ? 1 : -1) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index fa026559..d1060f84 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -338,7 +338,7 @@ end function gr_set_line(lw, style, c) #, a) GR.setlinetype(gr_linetype[style]) w, h = gr_plot_size - GR.setlinewidth(max(0, lw / ((w + h) * 0.001))) + GR.setlinewidth(_max(0, lw / ((w + h) * 0.001))) gr_set_linecolor(c) #, a) end @@ -391,7 +391,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi viewport[4] = viewport_canvas[4] * (1.0 - top(bb) / h) if is3d(sp) vp = viewport[:] - extent = min(vp[2] - vp[1], vp[4] - vp[3]) + extent = _min(vp[2] - vp[1], vp[4] - vp[3]) viewport[1] = 0.5 * (vp[1] + vp[2] - extent) viewport[2] = 0.5 * (vp[1] + vp[2] + extent) viewport[3] = 0.5 * (vp[3] + vp[4] - extent) @@ -425,7 +425,7 @@ function gr_set_viewport_polar() ymax -= 0.05 * (xmax - xmin) xcenter = 0.5 * (xmin + xmax) ycenter = 0.5 * (ymin + ymax) - r = 0.5 * min(xmax - xmin, ymax - ymin) + r = 0.5 * _min(xmax - xmin, ymax - ymin) GR.setviewport(xcenter -r, xcenter + r, ycenter - r, ycenter + r) GR.setwindow(-1, 1, -1, 1) r diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index c58ef884..85dd9c11 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -349,7 +349,7 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) ymin, ymax = axis_limits(yaxis) if ispolar(sp) #Plots.jl appears to give (xmin,xmax) ≜ (Θmin,Θmax) & (ymin,ymax) ≜ (rmin,rmax) - rmax = max(abs(ymin), abs(ymax)) + rmax = _max(abs(ymin), abs(ymax)) xmin, xmax = -rmax, rmax ymin, ymax = -rmax, rmax end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 579c1401..8bacb99e 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -926,14 +926,14 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = min(minval, _minimum(abs(v))) + minval = _min(minval, _minimum(abs(v))) end end end # now if the axis limits go to a smaller abs value, use that instead vmin, vmax = axis_limits(axis) - minval = min(minval, abs(vmin), abs(vmax)) + minval = _min(minval, abs(vmin), abs(vmax)) minval end @@ -954,7 +954,7 @@ function py_set_scale(ax, axis::Axis) elseif scale == :log10 10 end - kw[Symbol(:linthresh,letter)] = max(1e-16, py_compute_axis_minval(axis)) + kw[Symbol(:linthresh,letter)] = _max(1e-16, py_compute_axis_minval(axis)) "symlog" end func(arg; kw...) @@ -1096,10 +1096,10 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend}) bottompad = 0mm for bb in (py_bbox_axis(ax, "x"), py_bbox_axis(ax, "y"), py_bbox_title(ax)) if ispositive(width(bb)) && ispositive(height(bb)) - leftpad = max(leftpad, left(plotbb) - left(bb)) - toppad = max(toppad, top(plotbb) - top(bb)) - rightpad = max(rightpad, right(bb) - right(plotbb)) - bottompad = max(bottompad, bottom(bb) - bottom(plotbb)) + leftpad = _max(leftpad, left(plotbb) - left(bb)) + toppad = _max(toppad, top(plotbb) - top(bb)) + rightpad = _max(rightpad, right(bb) - right(plotbb)) + bottompad = _max(bottompad, bottom(bb) - bottom(plotbb)) end end diff --git a/src/layouts.jl b/src/layouts.jl index 9b123839..afd4e851 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -55,10 +55,10 @@ function Base.:+(bb1::BoundingBox, bb2::BoundingBox) ispositive(width(bb2)) || return bb1 ispositive(height(bb2)) || return bb1 - l = min(left(bb1), left(bb2)) - t = min(top(bb1), top(bb2)) - r = max(right(bb1), right(bb2)) - b = max(bottom(bb1), bottom(bb2)) + l = _min(left(bb1), left(bb2)) + t = _min(top(bb1), top(bb2)) + r = _max(right(bb1), right(bb2)) + b = _max(bottom(bb1), bottom(bb2)) BoundingBox(l, t, r-l, b-t) end diff --git a/src/recipes.jl b/src/recipes.jl index e575b645..13724b69 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - min(axis_limits(yaxis)[1], _minimum(y)) + _min(axis_limits(yaxis)[1], _minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -548,7 +548,7 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) - _cl(x) = max(ceil(Int, x), 1) + _cl(x) = _max(ceil(Int, x), 1) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) _span(v) = _maximum(v) - _minimum(v) diff --git a/src/utils.jl b/src/utils.jl index efdddb45..49f8521b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -6,7 +6,7 @@ function binData(data, nbins) lo, hi = _extrema(data) edges = collect(linspace(lo, hi, nbins+1)) 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] counts = zeros(Int, length(midpoints)) for b in buckets counts[b] += 1 @@ -284,8 +284,8 @@ unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[ function _expand_limits(lims, x) try e1, e2 = _extrema(x) - lims[1] = min(lims[1], e1) - lims[2] = max(lims[2], e2) + lims[1] = _min(lims[1], e1) + lims[2] = _max(lims[2], e2) # catch err # warn(err) end @@ -343,7 +343,7 @@ end function calc_r_extrema(x, y) xmin, xmax = _extrema(x) ymin, ymax = _extrema(y) - r = 0.5 * min(xmax - xmin, ymax - ymin) + r = 0.5 * _min(xmax - xmin, ymax - ymin) _extrema(r) end From 68adaf39ec74cd803f9cfe9beec400ea2ce3d96e Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 30 May 2017 21:58:28 +0200 Subject: [PATCH 17/17] Base NaN-compliant functions on NaNMath --- src/Plots.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index d17af86a..9eccdb1d 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -106,12 +106,17 @@ export # --------------------------------------------------------- +import NaNMath # define functions (e.g. `_extrema`, that ignores NaNs, when the type is applicable. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 for fun in (:extrema, :minimum, :maximum) - @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = Base.$(fun)(filter(!isnan,x)) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.$(fun)(x) @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end +for fun in (:min, :max) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::F, y::F) = NaNMath.$(fun)(x) + @eval $(Symbol(string("_",fun)))(x...) = Base.$(fun)(x...) +end # --------------------------------------------------------- import Measures