From 62280fb24bdea4feb18c092a0eff8ba4b95cc0ac Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sat, 26 Nov 2016 01:49:48 +0000 Subject: [PATCH] Modified error_coords to allow errorbars in plots with categorical x-axis --- src/recipes.jl | 3 +-- src/utils.jl | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 8ba9389f..fd9e2bec 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -526,8 +526,7 @@ end function error_coords(xorig, yorig, ebar) # init empty x/y, and zip errors if passed Tuple{Vector,Vector} - x, y = zeros(0), zeros(0) - + x, y = Array(float_extended_type(xorig), 0), Array(Float64, 0) # for each point, create a line segment from the bottom to the top of the errorbar for i = 1:max(length(xorig), length(yorig)) xi = cycle(xorig, i) diff --git a/src/utils.jl b/src/utils.jl index aefc1495..7c2af0fd 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -228,6 +228,12 @@ function Base.next(itr::SegmentsIterator, nextidx::Int) istart:iend, i end +# Find minimal type that can contain NaN and x +# To allow use of NaN separated segments with categorical x axis + +float_extended_type{T}(x::AbstractArray{T}) = Union{T,Float64} +float_extended_type{T<:Real}(x::AbstractArray{T}) = Float64 + # ------------------------------------------------------------------------------------