Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ end
function _add_errorbar_kw(kw_list::Vector{KW}, kw::AKW)
# handle error bars by creating new recipedata data... these will have
# the same recipedata index as the recipedata they are copied from
for esym in (:xerror, :yerror, :zerror)
if get(kw, esym, nothing) !== nothing
# we make a copy of the KW and apply an errorbar recipe
errkw = copy(kw)
errkw[:seriestype] = esym
errkw[:label] = ""
errkw[:primary] = false
push!(kw_list, errkw)
st = get(kw, :seriestype, :none)
errors = (:xerror, :yerror, :zerror)
if st ∉ errors
for esym in errors
if get(kw, esym, nothing) !== nothing
# we make a copy of the KW and apply an errorbar recipe
errkw = copy(kw)
errkw[:seriestype] = esym
errkw[:label] = ""
errkw[:primary] = false
push!(kw_list, errkw)
end
end
end
end
Expand Down Expand Up @@ -138,7 +142,7 @@ RecipesPipeline.get_axis_limits(plt::Plot, letter) = axis_limits(plt[1], letter,

## Plot recipes

RecipesPipeline.type_alias(plt::Plot) = get(_typeAliases, st, st)
RecipesPipeline.type_alias(plt::Plot, st) = get(_typeAliases, st, st)

## Plot setup

Expand All @@ -153,7 +157,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l
err_inds =
findall(kw -> get(kw, :seriestype, :path) in (:xerror, :yerror, :zerror), kw_list)
for ind in err_inds
if get(kw_list[ind - 1], :seriestype, :path) === :scatter
if ind > 1 && get(kw_list[ind - 1], :seriestype, :path) === :scatter
tmp = copy(kw_list[ind])
kw_list[ind] = copy(kw_list[ind - 1])
kw_list[ind - 1] = tmp
Expand Down
20 changes: 10 additions & 10 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ end
# ---------------------------------------------------------------------------
# Error Bars

function error_style!(plotattributes::AKW)
@attributes function error_style!(plotattributes::AKW)
# errorbar color should soley determined by markerstrokecolor
if haskey(plotattributes, :marker_z)
reset_kw!(plotattributes, :marker_z)
Expand All @@ -1156,12 +1156,12 @@ function error_style!(plotattributes::AKW)
msc
end

plotattributes[:seriestype] = :path
plotattributes[:markerstrokecolor] = msc
plotattributes[:markercolor] = msc
plotattributes[:linecolor] = msc
plotattributes[:linewidth] = plotattributes[:markerstrokewidth]
plotattributes[:label] = ""
seriestype := :path
markerstrokecolor --> msc
markercolor --> msc
linecolor --> msc
linewidth --> plotattributes[:markerstrokewidth]
label --> ""
end

# if we're passed a tuple of vectors, convert to a vector of tuples
Expand Down Expand Up @@ -1194,7 +1194,7 @@ clamp_to_eps!(ary) = (replace!(x -> x <= 0.0 ? Base.eps(Float64) : x, ary); noth

@recipe function f(::Type{Val{:xerror}}, x, y, z)
error_style!(plotattributes)
markershape := :vline
markershape --> :vline
xerr = error_zipit(plotattributes[:xerror])
if z === nothing
plotattributes[:x], plotattributes[:y] = error_coords(xerr, x, y)
Expand All @@ -1211,7 +1211,7 @@ end

@recipe function f(::Type{Val{:yerror}}, x, y, z)
error_style!(plotattributes)
markershape := :hline
markershape --> :hline
yerr = error_zipit(plotattributes[:yerror])
if z === nothing
plotattributes[:y], plotattributes[:x] = error_coords(yerr, y, x)
Expand All @@ -1228,7 +1228,7 @@ end

@recipe function f(::Type{Val{:zerror}}, x, y, z)
error_style!(plotattributes)
markershape := :hline
markershape --> :hline
if z !== nothing
zerr = error_zipit(plotattributes[:zerror])
plotattributes[:z], plotattributes[:x], plotattributes[:y] =
Expand Down
10 changes: 10 additions & 0 deletions src/shorthands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ for letter in ("x", "y", "z")
$(Symbol(letter, :grid!))(plt::PlotOrSubplot, args...; kw...) =
plot!(plt; $(Symbol(letter, :grid)) = args, kw...)
export $(Symbol(letter, :grid!))

"""
$($letter)error(x, y [, z]; $($letter)error = vals)
$($letter)error!(x, y [, z]; $($letter)error = vals)

Create or add a series of $($letter)errorbars at the positions defined by `x`, `y` and `z` with the lenghts defined in `vals`.

Markerstrokecolor will color the whole errorbars if not specified otherwise.
"""
@shorthands $(Symbol(letter, :error))
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/test_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,16 @@ end
@test Plots.seriestype_supported(Plots.UnicodePlotsBackend(), :hspan) === :recipe
@test Plots.seriestype_supported(Plots.NoBackend(), :line) === :no
end

@testset "error bars" begin
x = y = 1:10
yerror = fill(1, length(y))
xerror = fill(0.2, length(x))
p = Plots.xerror(x, y; xerror, linestyle = :solid)
plot!(p, x, y; linestyle = :dash)
yerror!(p, x, y; yerror, linestyle = :dot)
@test length(p.series_list) == 3
@test p[1][1][:linestyle] == :solid
@test p[1][2][:linestyle] == :dash
@test p[1][3][:linestyle] == :dot
end