From e851dcded2f2b27d6b48f462da621e2211e534af Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 4 Apr 2020 17:32:45 +0200 Subject: [PATCH] move remaining user recipes in series.jl to recipes.jl --- src/Plots.jl | 1 - src/recipes.jl | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ src/series.jl | 110 ------------------------------------------------ 3 files changed, 112 insertions(+), 111 deletions(-) delete mode 100644 src/series.jl diff --git a/src/Plots.jl b/src/Plots.jl index d8a3fe74..b6e0fe9f 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -189,7 +189,6 @@ include("args.jl") include("themes.jl") include("plot.jl") include("pipeline.jl") -include("series.jl") include("layouts.jl") include("subplots.jl") include("recipes.jl") diff --git a/src/recipes.jl b/src/recipes.jl index a0031712..fa5a35fb 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -1167,6 +1167,118 @@ end @deps quiver shape path +# -------------------------------------------------------------------- +# 1 argument +# -------------------------------------------------------------------- + +# images - grays +function clamp_greys!(mat::AMat{<:Gray}) + for i in eachindex(mat) + mat[i].val < 0 && (mat[i] = Gray(0)) + mat[i].val > 1 && (mat[i] = Gray(1)) + end + mat +end + +@recipe function f(mat::AMat{<:Gray}) + n, m = axes(mat) + if is_seriestype_supported(:image) + seriestype := :image + yflip --> true + SliceIt, m, n, Surface(clamp_greys!(mat)) + else + seriestype := :heatmap + yflip --> true + cbar --> false + fillcolor --> ColorGradient([:black, :white]) + SliceIt, m, n, Surface(clamp!(convert(Matrix{Float64}, mat), 0.0, 1.0)) + end +end + +# images - colors +@recipe function f(mat::AMat{T}) where {T <: Colorant} + n, m = axes(mat) + + if is_seriestype_supported(:image) + seriestype := :image + yflip --> true + SliceIt, m, n, Surface(mat) + else + seriestype := :heatmap + yflip --> true + cbar --> false + aspect_ratio --> :equal + z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) + SliceIt, m, n, Surface(z) + end +end + +# plotting arbitrary shapes/polygons + +@recipe function f(shape::Shape) + seriestype --> :shape + coords(shape) +end + +@recipe function f(shapes::AVec{Shape}) + seriestype --> :shape + coords(shapes) +end + +@recipe function f(shapes::AMat{Shape}) + seriestype --> :shape + for j in axes(shapes, 2) + @series coords(vec(shapes[:, j])) + end +end + + +# -------------------------------------------------------------------- +# 3 arguments +# -------------------------------------------------------------------- + +# images - grays +@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where {T <: Gray} + if is_seriestype_supported(:image) + seriestype := :image + yflip --> true + SliceIt, x, y, Surface(mat) + else + seriestype := :heatmap + yflip --> true + cbar --> false + fillcolor --> ColorGradient([:black, :white]) + SliceIt, x, y, Surface(convert(Matrix{Float64}, mat)) + end +end + +# images - colors +@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where {T <: Colorant} + if is_seriestype_supported(:image) + seriestype := :image + yflip --> true + SliceIt, x, y, Surface(mat) + else + seriestype := :heatmap + yflip --> true + cbar --> false + z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) + SliceIt, x, y, Surface(z) + end +end + +# -------------------------------------------------------------------- +# Lists of tuples and GeometryTypes.Points +# -------------------------------------------------------------------- +@recipe f(v::AVec{<:GeometryTypes.Point}) = unzip(v) +@recipe f(p::GeometryTypes.Point) = [p] + +# Special case for 4-tuples in :ohlc series +@recipe f(xyuv::AVec{<:Tuple{R1, R2, R3, R4}}) where {R1, R2, R3, R4} = + get(plotattributes, :seriestype, :path) == :ohlc ? OHLC[OHLC(t...) for t in xyuv] : + unzip(xyuv) + + # ------------------------------------------------- # TODO: move OHLC to PlotRecipes finance.jl diff --git a/src/series.jl b/src/series.jl deleted file mode 100644 index cfc1cc7a..00000000 --- a/src/series.jl +++ /dev/null @@ -1,110 +0,0 @@ -# -------------------------------------------------------------------- -# 1 argument -# -------------------------------------------------------------------- - -# images - grays -function clamp_greys!(mat::AMat{<:Gray}) - for i in eachindex(mat) - mat[i].val < 0 && (mat[i] = Gray(0)) - mat[i].val > 1 && (mat[i] = Gray(1)) - end - mat -end - -@recipe function f(mat::AMat{<:Gray}) - n, m = axes(mat) - if is_seriestype_supported(:image) - seriestype := :image - yflip --> true - SliceIt, m, n, Surface(clamp_greys!(mat)) - else - seriestype := :heatmap - yflip --> true - cbar --> false - fillcolor --> ColorGradient([:black, :white]) - SliceIt, m, n, Surface(clamp!(convert(Matrix{Float64}, mat), 0.0, 1.0)) - end -end - -# images - colors -@recipe function f(mat::AMat{T}) where {T <: Colorant} - n, m = axes(mat) - - if is_seriestype_supported(:image) - seriestype := :image - yflip --> true - SliceIt, m, n, Surface(mat) - else - seriestype := :heatmap - yflip --> true - cbar --> false - aspect_ratio --> :equal - z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) - SliceIt, m, n, Surface(z) - end -end - -# plotting arbitrary shapes/polygons - -@recipe function f(shape::Shape) - seriestype --> :shape - coords(shape) -end - -@recipe function f(shapes::AVec{Shape}) - seriestype --> :shape - coords(shapes) -end - -@recipe function f(shapes::AMat{Shape}) - seriestype --> :shape - for j in axes(shapes, 2) - @series coords(vec(shapes[:, j])) - end -end - - -# -------------------------------------------------------------------- -# 3 arguments -# -------------------------------------------------------------------- - -# images - grays -@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where {T <: Gray} - if is_seriestype_supported(:image) - seriestype := :image - yflip --> true - SliceIt, x, y, Surface(mat) - else - seriestype := :heatmap - yflip --> true - cbar --> false - fillcolor --> ColorGradient([:black, :white]) - SliceIt, x, y, Surface(convert(Matrix{Float64}, mat)) - end -end - -# images - colors -@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where {T <: Colorant} - if is_seriestype_supported(:image) - seriestype := :image - yflip --> true - SliceIt, x, y, Surface(mat) - else - seriestype := :heatmap - yflip --> true - cbar --> false - z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) - SliceIt, x, y, Surface(z) - end -end - -# -------------------------------------------------------------------- -# Lists of tuples and GeometryTypes.Points -# -------------------------------------------------------------------- -@recipe f(v::AVec{<:GeometryTypes.Point}) = unzip(v) -@recipe f(p::GeometryTypes.Point) = [p] - -# Special case for 4-tuples in :ohlc series -@recipe f(xyuv::AVec{<:Tuple{R1, R2, R3, R4}}) where {R1, R2, R3, R4} = - get(plotattributes, :seriestype, :path) == :ohlc ? OHLC[OHLC(t...) for t in xyuv] : - unzip(xyuv)