From 0985edba2afe61ab289f2cd6bcdfa97c134f2f88 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 1 Nov 2022 18:27:43 +0100 Subject: [PATCH 01/27] add attributes via `@add_attributes` --- RecipesBase/README.md | 4 +- RecipesBase/test/runtests.jl | 32 +++---- src/Plots.jl | 1 - src/arg_desc.jl | 18 ++-- src/args.jl | 122 ++++++++++++------------- src/backends.jl | 136 ++++++++++++++-------------- src/backends/deprecated/pgfplots.jl | 10 +- src/backends/gaston.jl | 8 +- src/backends/gr.jl | 40 ++++---- src/backends/inspectdr.jl | 20 ++-- src/backends/pgfplotsx.jl | 20 ++-- src/backends/plotly.jl | 36 ++++---- src/backends/pyplot.jl | 74 +++++++-------- src/backends/unicodeplots.jl | 6 +- src/components.jl | 37 +++++++- src/consts.jl | 2 +- src/pipeline.jl | 6 +- src/recipes.jl | 44 ++++----- src/utils.jl | 34 +++---- test/test_recipes.jl | 6 +- 20 files changed, 343 insertions(+), 313 deletions(-) diff --git a/RecipesBase/README.md b/RecipesBase/README.md index 84ce35455..09abd2cc2 100644 --- a/RecipesBase/README.md +++ b/RecipesBase/README.md @@ -125,8 +125,8 @@ function RecipesBase.apply_recipe(d::Dict{Symbol,Any},::T,n=1) end series_list = RecipesBase.RecipeData[] func_return = begin - get!(d,:markershape,:auto) - d[:markercolor] = customcolor + get!(d,:marker_shape,:auto) + d[:marker_color] = customcolor get!(d,:xrotation,45) get!(d,:zrotation,90) rand(10,n) diff --git a/RecipesBase/test/runtests.jl b/RecipesBase/test/runtests.jl index 93a09bb57..aa21882c3 100644 --- a/RecipesBase/test/runtests.jl +++ b/RecipesBase/test/runtests.jl @@ -66,8 +66,8 @@ end n::N = 1; customcolor = :green, ) where {N<:Integer} - :markershape --> :auto, :require - :markercolor --> customcolor, :force + :marker_shape --> :auto, :require + :marker_color --> customcolor, :force :xrotation --> 5 :zrotation --> 6, :quiet rand(StableRNG(1), 10, n) @@ -77,8 +77,8 @@ end T1, KW( :customcolor => :red, - :markershape => :auto, - :markercolor => :red, + :marker_shape => :auto, + :marker_color => :red, :xrotation => 5, :zrotation => 6, ), @@ -93,8 +93,8 @@ end n::N = 1; customcolor = :green, ) where {N<:Integer} - :markershape --> :auto, :require - :markercolor --> customcolor, :force + :marker_shape --> :auto, :require + :marker_color --> customcolor, :force :xrotation --> 5 :zrotation --> 6, :quiet rand(StableRNG(1), 10, n) @@ -104,8 +104,8 @@ end T2, KW( :customcolor => :red, - :markershape => :auto, - :markercolor => :red, + :marker_shape => :auto, + :marker_color => :red, :xrotation => 5, :zrotation => 6, ), @@ -121,8 +121,8 @@ end m::M = 0.0; customcolor = :green, ) where {N<:Integer} where {M<:Float64} - :markershape --> :auto, :require - :markercolor --> customcolor, :force + :marker_shape --> :auto, :require + :marker_color --> customcolor, :force :xrotation --> 5 :zrotation --> 6, :quiet rand(StableRNG(1), 10, n) @@ -132,8 +132,8 @@ end T3, KW( :customcolor => :red, - :markershape => :auto, - :markercolor => :red, + :marker_shape => :auto, + :marker_color => :red, :xrotation => 5, :zrotation => 6, ), @@ -144,8 +144,8 @@ end @test_throws MethodError RecipesBase.apply_recipe(KW(), T4()) RecipesBase.@recipe function plot(t::T4, n = 1; customcolor = :green) - :markershape --> :auto, :require - :markercolor --> customcolor, :force + :marker_shape --> :auto, :require + :marker_color --> customcolor, :force :xrotation --> 5 :zrotation --> 6, :quiet plotattributes[:hello] = "hi" @@ -156,8 +156,8 @@ end T4, KW( :customcolor => :red, - :markershape => :auto, - :markercolor => :red, + :marker_shape => :auto, + :marker_color => :red, :xrotation => 5, :zrotation => 6, :hello => "hi", diff --git a/src/Plots.jl b/src/Plots.jl index 59ce301d1..ceba660cf 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -50,7 +50,6 @@ import RecipesPipeline: timeformatter, needs_3d_axes, DefaultsDict, - explicitkeys, scale_func, is_surface, Formatted, diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ece7aa17b..0007561bd 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -6,21 +6,21 @@ const _arg_desc = KW( :seriescolor => "Color Type. The base color for this series. `:auto` (the default) will select a color from the subplot's `color_palette`, based on the order it was added to the subplot", :seriesalpha => "Number in [0,1]. The alpha/opacity override for the series. `nothing` (the default) means it will take the alpha value of the color.", :seriestype => "Symbol. This is the identifier of the type of visualization for this series. Choose from $(_allTypes) or any series recipes which are defined.", - :linestyle => "Symbol. Style of the line (for path and bar stroke). Choose from $(_allStyles)", - :linewidth => "Number. Width of the line (in pixels)", - :linecolor => "Color Type. Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default).", - :linealpha => "Number in [0,1]. The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor.", + :line_style => "Symbol. Style of the line (for path and bar stroke). Choose from $(_allStyles)", + :line_width => "Number. Width of the line (in pixels)", + :line_color => "Color Type. Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default).", + :line_alpha => "Number in [0,1]. The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor.", :fillrange => "Number or AbstractVector. Fills area between fillrange and y for line-types, sets the base for bar/stick types, and similar for other types.", :fillcolor => "Color Type. Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`.", :fillalpha => "Number in [0,1]. The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor.", - :markershape => "Symbol, Shape, or AbstractVector. Choose from $(_allMarkers).", + :marker_shape => "Symbol, Shape, or AbstractVector. Choose from $(_allMarkers).", :fillstyle => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", - :markercolor => "Color Type. Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`.", - :markeralpha => "Number in [0,1]. The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor.", + :marker_color => "Color Type. Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`.", + :marker_alpha => "Number in [0,1]. The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor.", :markersize => "Number or AbstractVector. Size (radius pixels) of the markers", :markerstrokestyle => "Symbol. Style of the marker stroke (border). Choose from $(_allStyles)", :markerstrokewidth => "Number. Width of the marker stroke (border) in pixels", - :markerstrokecolor => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.", + :marker_stroke_color => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.", :markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.", :bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `range(minimum(x), stop = maximum(x), length = 25)`", :smooth => "Bool. Add a regression line?", @@ -187,7 +187,7 @@ const _arg_desc = KW( :showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`", :widen => """ Bool, Number or :auto. Widen the axis limits by a small factor to avoid cut-off markers and lines at the borders. - If set to `true`, scale the axis limits by the default factor of $(default_widen_factor). + If set to `true`, scale the axis limits by the default factor of $(default_widen_factor). A different factor may be specified by setting `widen` to a number. Defaults to `:auto`, which widens by the default factor unless limits were manually set. See also the `scale_limits!` function for scaling axis limits in an existing plot. diff --git a/src/args.jl b/src/args.jl index 1336e1565..770f02449 100644 --- a/src/args.jl +++ b/src/args.jl @@ -325,21 +325,17 @@ const _series_defaults = KW( :seriescolor => :auto, :seriesalpha => nothing, :seriestype => :path, - :linestyle => :solid, - :linewidth => :auto, - :linecolor => :auto, - :linealpha => nothing, :fillrange => nothing, # ribbons, areas, etc :fillcolor => :match, :fillalpha => nothing, :fillstyle => nothing, - :markershape => :none, - :markercolor => :match, - :markeralpha => nothing, + :marker_shape => :none, + :marker_color => :match, + :marker_alpha => nothing, :markersize => 4, :markerstrokestyle => :solid, :markerstrokewidth => 1, - :markerstrokecolor => :match, + :marker_stroke_color => :match, :markerstrokealpha => nothing, :bins => :auto, # number of bins for hists :smooth => false, # regression line? @@ -613,9 +609,9 @@ add_aliases(:right_margin, :rightmargin) # colors add_aliases(:seriescolor, :c, :color, :colour) -add_aliases(:linecolor, :lc, :lcolor, :lcolour, :linecolour) -add_aliases(:markercolor, :mc, :mcolor, :mcolour, :markercolour) -add_aliases(:markerstrokecolor, :msc, :mscolor, :mscolour, :markerstrokecolour) +add_aliases(:line_color, :lc, :lcolor, :lcolour, :linecolour) +add_aliases(:marker_color, :mc, :mcolor, :mcolour, :markercolour) +add_aliases(:marker_stroke_color, :msc, :mscolor, :mscolour, :markerstrokecolour) add_aliases(:markerstrokewidth, :msw, :mswidth) add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) @@ -832,8 +828,8 @@ add_aliases( # alphas add_aliases(:seriesalpha, :alpha, :α, :opacity) -add_aliases(:linealpha, :la, :lalpha, :lα, :lineopacity, :lopacity) -add_aliases(:markeralpha, :ma, :malpha, :mα, :markeropacity, :mopacity) +add_aliases(:line_alpha, :la, :lalpha, :lα, :lineopacity, :lopacity) +add_aliases(:marker_alpha, :ma, :malpha, :mα, :markeropacity, :mopacity) add_aliases(:markerstrokealpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) @@ -915,10 +911,10 @@ add_axes_aliases( add_aliases(:seriestype, :st, :t, :typ, :linetype, :lt) add_aliases(:label, :lab) add_aliases(:line, :l) -add_aliases(:linewidth, :w, :width, :lw) -add_aliases(:linestyle, :style, :s, :ls) +add_aliases(:line_width, :w, :width, :lw) +add_aliases(:line_style, :style, :s, :ls) add_aliases(:marker, :m, :mark) -add_aliases(:markershape, :shape) +add_aliases(:marker_shape, :shape) add_aliases(:markersize, :ms, :msize) add_aliases(:marker_z, :markerz, :zcolor, :mz) add_aliases(:line_z, :linez, :zline, :lz) @@ -1126,16 +1122,16 @@ function processLineArg(plotattributes::AKW, arg) # linestyle elseif allStyles(arg) - plotattributes[:linestyle] = arg + plotattributes[:line_style] = arg elseif typeof(arg) <: Stroke - arg.width === nothing || (plotattributes[:linewidth] = arg.width) + arg.width === nothing || (plotattributes[:line_width] = arg.width) arg.color === nothing || ( - plotattributes[:linecolor] = + plotattributes[:line_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:linealpha] = arg.alpha) - arg.style === nothing || (plotattributes[:linestyle] = arg.style) + arg.alpha === nothing || (plotattributes[:line_alpha] = arg.alpha) + arg.style === nothing || (plotattributes[:line_style] = arg.style) elseif typeof(arg) <: Brush arg.size === nothing || (plotattributes[:fillrange] = arg.size) @@ -1151,14 +1147,14 @@ function processLineArg(plotattributes::AKW, arg) # linealpha elseif allAlphas(arg) - plotattributes[:linealpha] = arg + plotattributes[:line_alpha] = arg # linewidth elseif allReals(arg) - plotattributes[:linewidth] = arg + plotattributes[:line_width] = arg # color - elseif !handleColors!(plotattributes, arg, :linecolor) + elseif !handleColors!(plotattributes, arg, :line_color) @warn "Skipped line arg $arg." end end @@ -1166,7 +1162,7 @@ end function processMarkerArg(plotattributes::AKW, arg) # markershape if allShapes(arg) - plotattributes[:markershape] = arg + plotattributes[:marker_shape] = arg # stroke style elseif allStyles(arg) @@ -1175,7 +1171,7 @@ function processMarkerArg(plotattributes::AKW, arg) elseif typeof(arg) <: Stroke arg.width === nothing || (plotattributes[:markerstrokewidth] = arg.width) arg.color === nothing || ( - plotattributes[:markerstrokecolor] = + plotattributes[:marker_stroke_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) arg.alpha === nothing || (plotattributes[:markerstrokealpha] = arg.alpha) @@ -1184,25 +1180,25 @@ function processMarkerArg(plotattributes::AKW, arg) elseif typeof(arg) <: Brush arg.size === nothing || (plotattributes[:markersize] = arg.size) arg.color === nothing || ( - plotattributes[:markercolor] = + plotattributes[:marker_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:markeralpha] = arg.alpha) + arg.alpha === nothing || (plotattributes[:marker_alpha] = arg.alpha) # linealpha elseif allAlphas(arg) - plotattributes[:markeralpha] = arg + plotattributes[:marker_alpha] = arg # bool elseif typeof(arg) <: Bool - plotattributes[:markershape] = arg ? :circle : :none + plotattributes[:marker_shape] = arg ? :circle : :none # markersize elseif allReals(arg) plotattributes[:markersize] = arg # markercolor - elseif !handleColors!(plotattributes, arg, :markercolor) + elseif !handleColors!(plotattributes, arg, :marker_color) @warn "Skipped marker arg $arg." end end @@ -1374,9 +1370,9 @@ _replace_markershape(shape) = shape function _add_markershape(plotattributes::AKW) # add the markershape if it needs to be added... hack to allow "m=10" to add a shape, # and still allow overriding in _apply_recipe - ms = pop!(plotattributes, :markershape_to_add, :none) - if !haskey(plotattributes, :markershape) && ms !== :none - plotattributes[:markershape] = ms + ms = pop!(plotattributes, :marker_shape_to_add, :none) + if !haskey(plotattributes, :marker_shape) && ms !== :none + plotattributes[:marker_shape] = ms end end @@ -1503,15 +1499,15 @@ function preprocess_attributes!(plotattributes::AKW) anymarker = true end RecipesPipeline.reset_kw!(plotattributes, :marker) - if haskey(plotattributes, :markershape) - plotattributes[:markershape] = _replace_markershape(plotattributes[:markershape]) - if plotattributes[:markershape] === :none && + if haskey(plotattributes, :marker_shape) + plotattributes[:marker_shape] = _replace_markershape(plotattributes[:marker_shape]) + if plotattributes[:marker_shape] === :none && get(plotattributes, :seriestype, :path) in (:scatter, :scatterbins, :scatterhist, :scatter3d) #the default should be :auto, not :none, so that :none can be set explicitly and would be respected - plotattributes[:markershape] = :circle + plotattributes[:marker_shape] = :circle end elseif anymarker - plotattributes[:markershape_to_add] = :circle # add it after _apply_recipe + plotattributes[:marker_shape_to_add] = :circle # add it after _apply_recipe end # handle fill @@ -1593,7 +1589,7 @@ function warn_on_unsupported_args(pkg::AbstractBackend, plotattributes) Set{Symbol}() end extra_kwargs = Dict{Symbol,Any}() - for k in explicitkeys(plotattributes) + for k in RecipesPipeline.explicitkeys(plotattributes) is_attr_supported(pkg, k) && !(k in keys(_deprecated_attributes)) && continue k in _suppress_warnings && continue default_value = default(k) @@ -1629,10 +1625,10 @@ function warn_on_unsupported(pkg::AbstractBackend, plotattributes) get(plotattributes, :warn_on_unsupported, should_warn_on_unsupported(pkg)) || return is_seriestype_supported(pkg, plotattributes[:seriestype]) || @warn "seriestype $(plotattributes[:seriestype]) is unsupported with $pkg. Choose from: $(supported_seriestypes(pkg))" - is_style_supported(pkg, plotattributes[:linestyle]) || - @warn "linestyle $(plotattributes[:linestyle]) is unsupported with $pkg. Choose from: $(supported_styles(pkg))" - is_marker_supported(pkg, plotattributes[:markershape]) || - @warn "markershape $(plotattributes[:markershape]) is unsupported with $pkg. Choose from: $(supported_markers(pkg))" + is_style_supported(pkg, plotattributes[:line_style]) || + @warn "linestyle $(plotattributes[:line_style]) is unsupported with $pkg. Choose from: $(supported_styles(pkg))" + is_marker_supported(pkg, plotattributes[:marker_shape]) || + @warn "markershape $(plotattributes[:marker_shape]) is unsupported with $pkg. Choose from: $(supported_markers(pkg))" end function warn_on_unsupported_scales(pkg::AbstractBackend, plotattributes::AKW) @@ -2044,8 +2040,8 @@ ensure_gradient!(plotattributes::AKW, csym::Symbol, asym::Symbol) = _replace_linewidth(plotattributes::AKW) = # get a good default linewidth... 0 for surface and heatmaps - if plotattributes[:linewidth] === :auto - plotattributes[:linewidth] = ( + if plotattributes[:line_width] === :auto + plotattributes[:line_width] = ( get(plotattributes, :seriestype, :path) in (:surface, :heatmap, :image) ? 0 : 1 ) end @@ -2079,27 +2075,27 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) aliasesAndAutopick( plotattributes, - :linestyle, + :line_style, _styleAliases, supported_styles(pkg), plotIndex, ) aliasesAndAutopick( plotattributes, - :markershape, + :marker_shape, _markerAliases, supported_markers(pkg), plotIndex, ) # update alphas - for asym in (:linealpha, :markeralpha, :fillalpha) + for asym in (:line_alpha, :marker_alpha, :fillalpha) if plotattributes[asym] === nothing plotattributes[asym] = plotattributes[:seriesalpha] end end - if plotattributes[:markerstrokealpha] === nothing - plotattributes[:markerstrokealpha] = plotattributes[:markeralpha] + if plotattributes[:marker_stroke_alpha] === nothing + plotattributes[:marker_stroke_alpha] = plotattributes[:marker_alpha] end # update series color @@ -2108,7 +2104,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) plotattributes[:seriescolor] = scolor = get_series_color(scolor, sp, plotIndex, stype) # update other colors - for s in (:line, :marker, :fill) + for s in (:line_, :marker_, :fill) csym, asym = Symbol(s, :color), Symbol(s, :alpha) plotattributes[csym] = if plotattributes[csym] === :auto plot_color(if has_black_border_for_default(stype) && s === :line @@ -2124,20 +2120,20 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) end # update markerstrokecolor - plotattributes[:markerstrokecolor] = if plotattributes[:markerstrokecolor] === :match + plotattributes[:marker_stroke_color] = if plotattributes[:marker_stroke_color] === :match plot_color(sp[:foreground_color_subplot]) - elseif plotattributes[:markerstrokecolor] === :auto - get_series_color(plotattributes[:markercolor], sp, plotIndex, stype) + elseif plotattributes[:marker_stroke_color] === :auto + get_series_color(plotattributes[:marker_color], sp, plotIndex, stype) else - get_series_color(plotattributes[:markerstrokecolor], sp, plotIndex, stype) + get_series_color(plotattributes[:marker_stroke_color], sp, plotIndex, stype) end # if marker_z, fill_z or line_z are set, ensure we have a gradient if plotattributes[:marker_z] !== nothing - ensure_gradient!(plotattributes, :markercolor, :markeralpha) + ensure_gradient!(plotattributes, :marker_color, :marker_alpha) end if plotattributes[:line_z] !== nothing - ensure_gradient!(plotattributes, :linecolor, :linealpha) + ensure_gradient!(plotattributes, :line_color, :line_alpha) end if plotattributes[:fill_z] !== nothing ensure_gradient!(plotattributes, :fillcolor, :fillalpha) @@ -2145,9 +2141,9 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) # scatter plots don't have a line, but must have a shape if plotattributes[:seriestype] in (:scatter, :scatterbins, :scatterhist, :scatter3d) - plotattributes[:linewidth] = 0 - if plotattributes[:markershape] === :none - plotattributes[:markershape] = :circle + plotattributes[:line_width] = 0 + if plotattributes[:marker_shape] === :none + plotattributes[:marker_shape] = :circle end end @@ -2170,7 +2166,7 @@ _series_index(plotattributes, sp) = #-------------------------------------------------- ## inspired by Base.@kwdef """ - add_attributes(level, expr, match_table) + add_attributes(level, expr[, match_table]) Takes a `struct` definition and recurses into its fields to create keywords by chaining the field names with the structs' name with underscore. Also creates pluralized and non-underscore aliases for these keywords. @@ -2178,7 +2174,7 @@ Also creates pluralized and non-underscore aliases for these keywords. - `expr` is the struct definition with default values like `Base.@kwdef` - `match_table` is an expression of the form `:match = (symbols)`, with symbols whose default value should be `:match` """ -macro add_attributes(level, expr, match_table) +macro add_attributes(level, expr, match_table = :(:match = ())) expr = macroexpand(__module__, expr) # to expand @static expr isa Expr && expr.head === :struct || error("Invalid usage of @add_attributes") if (T = expr.args[2]) isa Expr && T.head === :<: diff --git a/src/backends.jl b/src/backends.jl index 9af12124b..73952b335 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -304,16 +304,16 @@ const _gr_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :fillrange, :fillcolor, @@ -436,16 +436,16 @@ const _plotly_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :markerstrokestyle, :fillrange, @@ -561,16 +561,16 @@ const _pgfplots_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :markerstrokestyle, :fillrange, @@ -676,16 +676,16 @@ const _pyplot_attr = merge_with_base_supported([ :foreground_color_guide, :foreground_color_text, :label, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :fillrange, :fillcolor, @@ -797,15 +797,15 @@ const _gaston_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, - # :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokestyle, + :marker_alpha, + # :markerstrokewidth, :marker_stroke_color, :markerstrokealpha, :markerstrokestyle, # :fillrange, :fillcolor, :fillalpha, # :bins, # :bar_width, :bar_edges, @@ -897,10 +897,10 @@ const _unicodeplots_attr = merge_with_base_supported([ :layout, :legend, :lims, - :linealpha, - :linecolor, - :linestyle, - :markershape, + :line_alpha, + :line_color, + :line_style, + :marker_shape, :quiver, :arrow, :seriesalpha, @@ -977,16 +977,16 @@ const _hdf5_attr = merge_with_base_supported([ :foreground_color_guide, :foreground_color_text, :label, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :fillrange, :fillcolor, @@ -1082,16 +1082,16 @@ const _inspectdr_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :markerstrokestyle, #Causes warning not to have it... what is this? :fillcolor, @@ -1184,16 +1184,16 @@ const _pgfplotsx_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, :markersize, - :markeralpha, + :marker_alpha, :markerstrokewidth, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :fillrange, :fillcolor, diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 3e992dba8..04f6c08f9 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -107,8 +107,8 @@ end function pgf_linestyle(plotattributes, i = 1) lw = pgf_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i) - lc = get_linecolor(plotattributes, i) - la = get_linealpha(plotattributes, i) + lc = get_line_color(plotattributes, i) + la = get_line_alpha(plotattributes, i) ls = get_linestyle(plotattributes, i) return pgf_linestyle(lw, lc, la, ls) end @@ -119,9 +119,9 @@ function pgf_font(fontsize, thickness_scaling = 1, font = "\\selectfont") end function pgf_marker(plotattributes, i = 1) - shape = _cycle(plotattributes[:markershape], i) + shape = _cycle(plotattributes[:marker_shape], i) cstr, a = pgf_color( - plot_color(get_markercolor(plotattributes, i), get_markeralpha(plotattributes, i)), + plot_color(get_marker_color(plotattributes, i), get_marker_alpha(plotattributes, i)), ) cstr_stroke, a_stroke = pgf_color( plot_color( @@ -641,7 +641,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # As it is likely that all series within the same axis use the same # colormap this should not cause any problem. for series in series_list(sp) - for col in (:markercolor, :fillcolor, :linecolor) + for col in (:marker_color, :fillcolor, :line_color) if typeof(series.plotattributes[col]) == ColorGradient push!( style, diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index f772f23ee..7558da604 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -302,7 +302,7 @@ function gaston_seriesconf!( curveconf, "w filledcurves fc $fc fs solid border lc $lc lw $lw dt $dt,'' w lines lc $lc lw $lw dt $dt", ) - elseif series[:markershape] === :none # simplepath + elseif series[:marker_shape] === :none # simplepath push!(curveconf, "w lines lc $lc dt $dt lw $lw") else pt, ps, mc = gaston_mk_ms_mc(series, clims, i) @@ -520,15 +520,15 @@ gaston_valign(k) = (top = :top, vcenter = :center, bottom = :bottom)[k] gaston_alpha(alpha) = alpha === nothing ? 0 : alpha gaston_lc_ls_lw(series::Series, clims, i::Int) = ( - gaston_color(get_linecolor(series, clims, i), get_linealpha(series, i)), + gaston_color(get_line_color(series, clims, i), get_line_alpha(series, i)), gaston_linestyle(get_linestyle(series, i)), get_linewidth(series, i), ) gaston_mk_ms_mc(series::Series, clims, i::Int) = ( - gaston_marker(_cycle(series[:markershape], i), get_markeralpha(series, i)), + gaston_marker(_cycle(series[:marker_shape], i), get_marker_alpha(series, i)), _cycle(series[:markersize], i) * 1.3 / 5, - gaston_color(get_markercolor(series, clims, i), get_markeralpha(series, i)), + gaston_color(get_marker_color(series, clims, i), get_marker_alpha(series, i)), ) function gaston_font(f; rot = true, align = true, color = true, scale = 1) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d1320a7a8..9fd96581d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -367,9 +367,9 @@ function gr_draw_marker(series, xi, yi, zi, clims, i, msize, strokewidth, shape: xs, ys = getindex.(xs_ys, 1), getindex.(xs_ys, 2) # draw the interior - mc = get_markercolor(series, clims, i) + mc = get_marker_color(series, clims, i) gr_set_fill(mc) - gr_set_transparency(mc, get_markeralpha(series, i)) + gr_set_transparency(mc, get_marker_alpha(series, i)) GR.fillarea(xs, ys) # draw the shapes @@ -384,8 +384,8 @@ end function gr_draw_marker(series, xi, yi, zi, clims, i, msize, strokewidth, shape::Symbol) GR.setborderwidth(strokewidth) gr_set_bordercolor(get_markerstrokecolor(series, i)) - gr_set_markercolor(get_markercolor(series, clims, i)) - gr_set_transparency(get_markeralpha(series, i)) + gr_set_markercolor(get_marker_color(series, clims, i)) + gr_set_transparency(get_marker_alpha(series, i)) GR.setmarkertype(gr_markertypes[shape]) GR.setmarkersize(0.3msize / gr_nominal_size(series)) if zi === nothing @@ -583,10 +583,10 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, vp::GRViewport) gr_set_line( _cbar_unique(get_linewidth.(series), "line width"), _cbar_unique(get_linestyle.(series), "line style"), - _cbar_unique(get_linecolor.(series, Ref(clims)), "line color"), + _cbar_unique(get_line_color.(series, Ref(clims)), "line color"), sp, ) - gr_set_transparency(_cbar_unique(get_linealpha.(series), "line alpha")) + gr_set_transparency(_cbar_unique(get_line_alpha.(series), "line alpha")) levels = _cbar_unique(contour_levels.(series, Ref(clims)), "levels") colors = gr_colorbar_colors(last(series), clims) for (line, color) in zip(levels, colors) @@ -1005,7 +1005,7 @@ function gr_add_legend(sp, leg, viewport_area) should_add_to_legend(series) || continue st = series[:seriestype] clims = gr_clims(sp, series) - lc = get_linecolor(series, clims) + lc = get_line_color(series, clims) gr_set_line(lfps / 8, get_linestyle(series), lc, sp) _debugMode[] && gr_legend_bbox(xpos, ypos, leg) @@ -1026,8 +1026,8 @@ function gr_add_legend(sp, leg, viewport_area) x, y = [l, r, r, l, l], [b, b, t, t, b] gr_set_transparency(fc, get_fillalpha(series)) gr_polyline(x, y, GR.fillarea) - lc = get_linecolor(series, clims) - gr_set_transparency(lc, get_linealpha(series)) + lc = get_line_color(series, clims) + gr_set_transparency(lc, get_line_alpha(series)) gr_set_line(get_linewidth(series), get_linestyle(series), lc, sp) st === :shape && gr_polyline(x, y) end @@ -1040,7 +1040,7 @@ function gr_add_legend(sp, leg, viewport_area) GR.polyline(xpos .+ [lft, rgt], ypos .+ (filled ? [top, top] : [0, 0])) end - if (msh = series[:markershape]) !== :none + if (msh = series[:marker_shape]) !== :none msz = first(series[:markersize]) msw = first(series[:markerstrokewidth]) gr_draw_marker( @@ -1673,14 +1673,14 @@ function gr_add_series(sp, series) x, y = straightline_data(series) end gr_draw_segments(series, x, y, nothing, frng, clims) - if series[:markershape] !== :none + if series[:marker_shape] !== :none gr_draw_markers(series, x, y, nothing, clims) end elseif st === :shape gr_draw_shapes(series, clims) elseif st in (:path3d, :scatter3d) gr_draw_segments(series, x, y, z, nothing, clims) - if st === :scatter3d || series[:markershape] !== :none + if st === :scatter3d || series[:marker_shape] !== :none gr_draw_markers(series, x, y, z, clims) end elseif st === :contour @@ -1744,9 +1744,9 @@ function gr_draw_segments(series, x, y, z, fillrange, clims) gr_set_transparency(fc, get_fillalpha(series, i)) GR.fillarea(fx, fy) end - (lc = get_linecolor(series, clims, i)) |> gr_set_fillcolor + (lc = get_line_color(series, clims, i)) |> gr_set_fillcolor gr_set_line(get_linewidth(series, i), get_linestyle(series, i), lc, series) - gr_set_transparency(lc, get_linealpha(series, i)) + gr_set_transparency(lc, get_line_alpha(series, i)) if is3d GR.polyline3d(x[rng], y[rng], z[rng]) elseif is2d @@ -1771,7 +1771,7 @@ function gr_draw_markers( ) isempty(x) && return GR.setfillintstyle(GR.INTSTYLE_SOLID) - (shapes = series[:markershape]) === :none && return + (shapes = series[:marker_shape]) === :none && return for segment in series_segments(series, :scatter) rng = intersect(eachindex(IndexLinear(), x), segment.range) isempty(rng) && continue @@ -1815,9 +1815,9 @@ function gr_draw_shapes(series, clims) GR.fillarea(xseg, yseg) # draw the shapes - lc = get_linecolor(series, clims, i) + lc = get_line_color(series, clims, i) gr_set_line(get_linewidth(series, i), get_linestyle(series, i), lc, series) - gr_set_transparency(lc, get_linealpha(series, i)) + gr_set_transparency(lc, get_line_alpha(series, i)) GR.polyline(xseg, yseg) end end @@ -1826,14 +1826,14 @@ end function gr_draw_contour(series, x, y, z, clims) GR.setprojectiontype(0) GR.setspace(clims[1], clims[2], 0, 90) - gr_set_line(get_linewidth(series), get_linestyle(series), get_linecolor(series), series) + gr_set_line(get_linewidth(series), get_linestyle(series), get_line_color(series), series) gr_set_transparency(get_fillalpha(series)) h = gr_contour_levels(series, clims) if series[:fillrange] !== nothing GR.contourf(x, y, h, z, series[:contour_labels] == true ? 1 : 0) else black = plot_color(:black) - coff = plot_color(series[:linecolor]) in (black, [black]) ? 0 : 1_000 + coff = plot_color(series[:line_color]) in (black, [black]) ? 0 : 1_000 GR.contour(x, y, h, z, coff + (series[:contour_labels] == true ? 1 : 0)) end nothing @@ -1893,7 +1893,7 @@ function gr_draw_surface(series, x, y, z, clims) fillalpha = get_fillalpha(series) facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor) GR.setborderwidth(get_linewidth(series)) - GR.setbordercolorind(gr_getcolorind(get_linecolor(series))) + GR.setbordercolorind(gr_getcolorind(get_line_color(series))) GR.polygonmesh3d(x, y, z, vcat(cns...), signed.(gr_color.(facecolor))) else throw(ArgumentError("Not handled !")) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 337c47e06..4f0e6f932 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -253,8 +253,8 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) for (i, rng) in enumerate(iter_segments(x, y)) nmax = i if length(rng) > 1 - linewidth = series[:linewidth] - c = plot_color(get_linecolor(series), get_linealpha(series)) + linewidth = series[:line_width] + c = plot_color(get_line_color(series), get_line_alpha(series)) linecolor = _inspectdr_mapcolor(_cycle(c, i)) c = plot_color(get_fillcolor(series), get_fillalpha(series)) fillcolor = _inspectdr_mapcolor(_cycle(c, i)) @@ -271,8 +271,8 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) i = (nmax >= 2 ? div(nmax, 2) : nmax) #Must pick one set of colors for legend if i > 1 #Add dummy waveform for legend entry: - linewidth = series[:linewidth] - c = plot_color(get_linecolor(series), get_linealpha(series)) + linewidth = series[:line_width] + c = plot_color(get_line_color(series), get_line_alpha(series)) linecolor = _inspectdr_mapcolor(_cycle(c, i)) c = plot_color(get_fillcolor(series), get_fillalpha(series)) fillcolor = _inspectdr_mapcolor(_cycle(c, i)) @@ -290,14 +290,14 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) end elseif st in (:path, :scatter, :straightline) #, :steppre, :stepmid, :steppost) # NOTE: In Plots.jl, :scatter plots have 0-linewidths (I think). - linewidth = series[:linewidth] + linewidth = series[:line_width] # More efficient & allows some support for markerstrokewidth: - _style = (0 == linewidth ? :none : series[:linestyle]) + _style = (0 == linewidth ? :none : series[:line_style]) wfrm = InspectDR.add(plot, x, y, id = series[:label]) wfrm.line = InspectDR.line( style = _style, - width = series[:linewidth], - color = plot_color(get_linecolor(series), get_linealpha(series)), + width = series[:line_width], + color = plot_color(get_line_color(series), get_line_alpha(series)), ) # InspectDR does not control markerstrokewidth independently. if _style === :none @@ -305,13 +305,13 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) wfrm.line.width = series[:markerstrokewidth] end wfrm.glyph = InspectDR.glyph( - shape = _inspectdr_mapglyph(series[:markershape]), + shape = _inspectdr_mapglyph(series[:marker_shape]), size = _inspectdr_mapglyphsize(series[:markersize]), color = _inspectdr_mapcolor( plot_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), ), fillcolor = _inspectdr_mapcolor( - plot_color(get_markercolor(series, clims), get_markeralpha(series)), + plot_color(get_marker_color(series, clims), get_marker_alpha(series)), ), ) end diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 2a12fccb3..3de0c14d3 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -267,7 +267,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) extra_series, extra_series_opt = pgfx_split_extra_kw(series[:extra_kwargs]) series_opt = merge( Options( - "color" => single_color(opt[:linecolor]), + "color" => single_color(opt[:line_color]), "name path" => string(series_id), ), Options(extra_series_opt...), @@ -338,8 +338,8 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o for (k, segment) in enumerate(segments) i, rng = segment.attr_index, segment.range segment_opt = merge(Options(), pgfx_linestyle(opt, i)) - if opt[:markershape] !== :none - if (marker = _cycle(opt[:markershape], i)) isa Shape + if opt[:marker_shape] !== :none + if (marker = _cycle(opt[:marker_shape], i)) isa Shape scale_factor = 0.00125 msize = opt[:markersize] * scale_factor path = join( @@ -437,7 +437,7 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o end # for segments # get that last marker - if !isnothing(opt[:y]) && !any(isnan, opt[:y]) && opt[:markershape] isa AVec + if !isnothing(opt[:y]) && !any(isnan, opt[:y]) && opt[:marker_shape] isa AVec push!( axis, PGFPlotsX.PlotInc( # additional plot @@ -893,8 +893,8 @@ pgfx_legend_col(n) = n function pgfx_linestyle(plotattributes, i = 1) lw = pgfx_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i) - lc = single_color(get_linecolor(plotattributes, i)) - la = get_linealpha(plotattributes, i) + lc = single_color(get_line_color(plotattributes, i)) + la = get_line_alpha(plotattributes, i) ls = get_linestyle(plotattributes, i) return pgfx_linestyle(lw, lc, la, ls) end @@ -925,9 +925,9 @@ pgfx_should_add_to_legend(series::Series) = ) function pgfx_marker(plotattributes, i = 1) - shape = _cycle(plotattributes[:markershape], i) + shape = _cycle(plotattributes[:marker_shape], i) cstr = - plot_color(get_markercolor(plotattributes, i), get_markeralpha(plotattributes, i)) + plot_color(get_marker_color(plotattributes, i), get_marker_alpha(plotattributes, i)) cstr_stroke = plot_color( get_markerstrokecolor(plotattributes, i), get_markerstrokealpha(plotattributes, i), @@ -936,8 +936,8 @@ function pgfx_marker(plotattributes, i = 1) pgfx_thickness_scaling(plotattributes) * 0.75 * _cycle(plotattributes[:markersize], i) - mark_freq = if !any(isnan, plotattributes[:y]) && plotattributes[:markershape] isa AVec - length(plotattributes[:markershape]) + mark_freq = if !any(isnan, plotattributes[:y]) && plotattributes[:marker_shape] isa AVec + length(plotattributes[:marker_shape]) else 1 end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 35958bc14..1c4cbbc7f 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -97,7 +97,7 @@ function plotly_axis(axis, sp, anchor = nothing, domain = nothing) :zeroline => framestyle === :zerolines, :zerolinecolor => rgba_string(axis[:foreground_color_axis]), :showline => framestyle in (:box, :axes) && axis[:showaxis], - :linecolor => rgba_string(plot_color(axis[:foreground_color_axis])), + :line_color => rgba_string(plot_color(axis[:foreground_color_axis])), :ticks => axis[:tick_direction] === :out ? "outside" : axis[:tick_direction] === :in ? "inside" : "", @@ -121,7 +121,7 @@ function plotly_axis(axis, sp, anchor = nothing, domain = nothing) ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) - ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) + ax[:line_color] = rgba_string(axis[:foreground_color_axis]) # ticks if axis[:ticks] !== :native @@ -540,7 +540,7 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:name] = series[:label] isscatter = st in (:scatter, :scatter3d, :scattergl) - hasmarker = isscatter || series[:markershape] !== :none + hasmarker = isscatter || series[:marker_shape] !== :none hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && @@ -598,7 +598,7 @@ function plotly_series(plt::Plot, series::Series) end end plotattributes_out[:colorscale] = - plotly_colorscale(series[:linecolor], series[:linealpha]) + plotly_colorscale(series[:line_color], series[:line_alpha]) plotattributes_out[:showscale] = hascolorbar(sp) && hascolorbar(series) elseif st in (:surface, :wireframe) @@ -609,8 +609,8 @@ function plotly_series(plt::Plot, series::Series) wirelines = KW( :show => true, :color => - rgba_string(plot_color(series[:linecolor], series[:linealpha])), - :highlightwidth => series[:linewidth], + rgba_string(plot_color(series[:line_color], series[:line_alpha])), + :highlightwidth => series[:line_width], ) plotattributes_out[:contours] = KW(:x => wirelines, :y => wirelines, :z => wirelines) @@ -679,14 +679,14 @@ function plotly_series(plt::Plot, series::Series) inds = eachindex(x) plotattributes_out[:marker] = KW( :symbol => - get_plotly_marker(series[:markershape], string(series[:markershape])), - # :opacity => series[:markeralpha], + get_plotly_marker(series[:marker_shape], string(series[:marker_shape])), + # :opacity => series[:marker_alpha], :size => 2_cycle(series[:markersize], inds), :color => rgba_string.( plot_color.( - get_markercolor.(series, inds), - get_markeralpha.(series, inds), + get_marker_color.(series, inds), + get_marker_alpha.(series, inds), ), ), :line => KW( @@ -750,7 +750,7 @@ function plotly_series_shapes(plt::Plot, series::Series, clims) if series[:markerstrokewidth] > 0 plotattributes_out[:line] = KW( :color => rgba_string( - plot_color(get_linecolor(series, clims, i), get_linealpha(series, i)), + plot_color(get_line_color(series, clims, i), get_line_alpha(series, i)), ), :width => get_linewidth(series, i), :dash => string(get_linestyle(series, i)), @@ -778,7 +778,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z st = series[:seriestype] sp = series[:subplot] isscatter = st in (:scatter, :scatter3d, :scattergl) - hasmarker = isscatter || series[:markershape] !== :none + hasmarker = isscatter || series[:marker_shape] !== :none hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && @@ -835,12 +835,12 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z # add "marker" if hasmarker mcolor = rgba_string( - plot_color(get_markercolor(series, clims, i), get_markeralpha(series, i)), + plot_color(get_marker_color(series, clims, i), get_marker_alpha(series, i)), ) mcolor_next = if (mz = series[:marker_z]) !== nothing && i < length(mz) plot_color( - get_markercolor(series, clims, i + 1), - get_markeralpha(series, i + 1), + get_marker_color(series, clims, i + 1), + get_marker_alpha(series, i + 1), ) |> rgba_string else mcolor @@ -859,8 +859,8 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z plotattributes_out[:marker] = KW( :symbol => get_plotly_marker( - _cycle(series[:markershape], i), - string(_cycle(series[:markershape], i)), + _cycle(series[:marker_shape], i), + string(_cycle(series[:marker_shape], i)), ), # :opacity => needs_scatter_fix ? [1, 0] : 1, :size => 2_cycle(series[:markersize], i), @@ -876,7 +876,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z if hasline plotattributes_out[:line] = KW( :color => rgba_string( - plot_color(get_linecolor(series, clims, i), get_linealpha(series, i)), + plot_color(get_line_color(series, clims, i), get_line_alpha(series, i)), ), :width => get_linewidth(series, i), :shape => if st === :steppre diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 0550832b3..76a5bb194 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -242,9 +242,9 @@ function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series) end py_linecolormap(series::Series) = - py_colormap(cgrad(series[:linecolor], alpha = get_linealpha(series))) + py_colormap(cgrad(series[:line_color], alpha = get_line_alpha(series))) py_markercolormap(series::Series) = - py_colormap(cgrad(series[:markercolor], alpha = get_markeralpha(series))) + py_colormap(cgrad(series[:marker_color], alpha = get_marker_alpha(series))) py_fillcolormap(series::Series) = py_colormap(cgrad(series[:fillcolor], alpha = get_fillalpha(series))) @@ -440,7 +440,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # line plot if st in (:path, :path3d, :steppre, :stepmid, :steppost, :straightline) - if maximum(series[:linewidth]) > 0 + if maximum(series[:line_width]) > 0 for (k, segment) in enumerate(series_segments(series, st; check = true)) i, rng = segment.attr_index, segment.range handle = ax."plot"( @@ -448,8 +448,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = k == 1 ? series[:label] : "", zorder = series[:series_plotindex], color = py_color( - single_color(get_linecolor(series, clims, i)), - get_linealpha(series, i), + single_color(get_line_color(series, clims, i)), + get_line_alpha(series, i), ), linewidth = py_thickness_scale(plt, get_linewidth(series, i)), linestyle = py_linestyle(st, get_linestyle(series, i)), @@ -469,10 +469,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) :arrowstyle => "simple,head_length=$(a.headlength),head_width=$(a.headwidth)", :shrinkA => 0, :shrinkB => 0, - :edgecolor => py_color(get_linecolor(series)), - :facecolor => py_color(get_linecolor(series)), - :linewidth => py_thickness_scale(plt, get_linewidth(series)), - :linestyle => py_linestyle(st, get_linestyle(series)), + :edgecolor => py_color(get_line_color(series)), + :facecolor => py_color(get_line_color(series)), + :line_width => py_thickness_scale(plt, get_linewidth(series)), + :line_style => py_linestyle(st, get_linestyle(series)), ) add_arrows(x, y) do xyprev, xy ax."annotate"( @@ -492,7 +492,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end # add markers? - if series[:markershape] !== :none && + if series[:marker_shape] !== :none && st in (:path, :scatter, :path3d, :scatter3d, :steppre, :stepmid, :steppost, :bar) for segment in series_segments(series, :scatter) i, rng = segment.attr_index, segment.range @@ -509,11 +509,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) args...; label = series[:label], zorder = series[:series_plotindex] + 0.5, - marker = py_marker(_cycle(series[:markershape], i)), + marker = py_marker(_cycle(series[:marker_shape], i)), s = py_thickness_scale(plt, _cycle(series[:markersize], i)) .^ 2, facecolors = py_color( - get_markercolor(series, i), - get_markeralpha(series, i), + get_marker_color(series, i), + get_marker_alpha(series, i), ), edgecolors = py_color( get_markerstrokecolor(series, i), @@ -529,14 +529,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) if st === :hexbin sekw = series[:extra_kwargs] extrakw[:mincnt] = get(sekw, :mincnt, nothing) - extrakw[:edgecolors] = get(sekw, :edgecolors, py_color(get_linecolor(series))) + extrakw[:edgecolors] = get(sekw, :edgecolors, py_color(get_line_color(series))) handle = ax."hexbin"( x, y; label = series[:label], C = series[:weights], gridsize = series[:bins] === :auto ? 100 : series[:bins], # 100 is the default value - linewidths = py_thickness_scale(plt, series[:linewidth]), + linewidths = py_thickness_scale(plt, series[:line_width]), alpha = series[:fillalpha], cmap = py_fillcolormap(series), # applies to the pcolorfast object zorder = series[:series_plotindex], @@ -553,8 +553,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end end - if typeof(series[:linecolor]) <: AbstractArray - extrakw[:colors] = py_color.(series[:linecolor]) + if typeof(series[:line_color]) <: AbstractArray + extrakw[:colors] = py_color.(series[:line_color]) else extrakw[:cmap] = py_linecolormap(series) end @@ -567,8 +567,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) levelargs...; label = series[:label], zorder = series[:series_plotindex], - linewidths = py_thickness_scale(plt, series[:linewidth]), - linestyles = py_linestyle(st, series[:linestyle]), + linewidths = py_thickness_scale(plt, series[:line_width]), + linestyles = py_linestyle(st, series[:line_style]), extrakw..., ) if series[:contour_labels] == true @@ -615,8 +615,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) zorder = series[:series_plotindex], rstride = series[:stride][1], cstride = series[:stride][2], - linewidth = py_thickness_scale(plt, series[:linewidth]), - edgecolor = py_color(get_linecolor(series)), + linewidth = py_thickness_scale(plt, series[:line_width]), + edgecolor = py_color(get_line_color(series)), extrakw..., ) push!(handles, handle) @@ -647,8 +647,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = series[:label], zorder = series[:series_plotindex], cmap = py_fillcolormap(series), - linewidth = py_thickness_scale(plt, series[:linewidth]), - edgecolor = py_color(get_linecolor(series)), + linewidth = py_thickness_scale(plt, series[:line_width]), + edgecolor = py_color(get_line_color(series)), extrakw..., ) push!(handles, handle) @@ -683,8 +683,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end col = mplot3d.art3d.Poly3DCollection( polygons, - linewidths = py_thickness_scale(plt, series[:linewidth]), - edgecolor = py_color(get_linecolor(series)), + linewidths = py_thickness_scale(plt, series[:line_width]), + edgecolor = py_color(get_line_color(series)), facecolor = py_color(series[:fillcolor]), alpha = get_fillalpha(series), zorder = series[:series_plotindex], @@ -693,7 +693,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # Fix for handle: https://stackoverflow.com/questions/54994600/pyplot-legend-poly3dcollection-object-has-no-attribute-edgecolors2d # It seems there aren't two different alpha values for edge and face handle._facecolors2d = py_color(series[:fillcolor]) - handle._edgecolors2d = py_color(get_linecolor(series)) + handle._edgecolors2d = py_color(get_line_color(series)) push!(handles, handle) end @@ -741,7 +741,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) zorder = series[:series_plotindex], cmap = py_fillcolormap(series), alpha = series[:fillalpha], - # edgecolors = (series[:linewidth] > 0 ? py_linecolor(series) : "face"), + # edgecolors = (series[:line_width] > 0 ? py_linecolor(series) : "face"), extrakw..., ) push!(handles, handle) @@ -752,9 +752,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) for segment in series_segments(series) i, rng = segment.attr_index, segment.range if length(rng) > 1 - lc = get_linecolor(series, clims, i) + lc = get_line_color(series, clims, i) fc = get_fillcolor(series, clims, i) - la = get_linealpha(series, i) + la = get_line_alpha(series, i) fa = get_fillalpha(series, i) ls = get_linestyle(series, i) fs = get_fillstyle(series, i) @@ -818,7 +818,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) dim1, _cycle(fillrange[1], rng), _cycle(fillrange[2], rng) end - la = get_linealpha(series, i) + la = get_line_alpha(series, i) fc = get_fillcolor(series, clims, i) fa = get_fillalpha(series, i) fs = get_fillstyle(series, i) @@ -1467,9 +1467,9 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) clims = get_clims(sp, series) # add a line/marker and a label if series[:seriestype] === :shape || series[:fillrange] !== nothing - lc = get_linecolor(series, clims) + lc = get_line_color(series, clims) fc = get_fillcolor(series, clims) - la = get_linealpha(series) + la = get_line_alpha(series) fa = get_fillalpha(series) ls = get_linestyle(series) fs = get_fillstyle(series) @@ -1508,8 +1508,8 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) (0, 1), (0, 0), color = py_color( - single_color(get_linecolor(series, clims)), - get_linealpha(series), + single_color(get_line_color(series, clims)), + get_line_alpha(series), ), linewidth = py_thickness_scale( plt, @@ -1520,15 +1520,15 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) solid_joinstyle = "miter", dash_capstyle = "butt", dash_joinstyle = "miter", - marker = py_marker(_cycle(series[:markershape], 1)), + marker = py_marker(_cycle(series[:marker_shape], 1)), markersize = py_thickness_scale(plt, 0.8sp[:legend_font_pointsize]), markeredgecolor = py_color( single_color(get_markerstrokecolor(series)), get_markerstrokealpha(series), ), markerfacecolor = py_color( - single_color(get_markercolor(series, clims)), - get_markeralpha(series), + single_color(get_marker_color(series, clims)), + get_marker_alpha(series), ), markeredgewidth = py_thickness_scale( plt, diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 4c98a15fb..2ec45797b 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -233,9 +233,9 @@ function addUnicodeSeries!( if st in (:path, :path3d, :straightline, :shape, :mesh3d) func = UnicodePlots.lineplot! series_kw = (; head_tail = series[:arrow] isa Arrow ? series[:arrow].side : nothing) - elseif st in (:scatter, :scatter3d) || series[:markershape] !== :none + elseif st in (:scatter, :scatter3d) || series[:marker_shape] !== :none func = UnicodePlots.scatterplot! - series_kw = (; marker = series[:markershape]) + series_kw = (; marker = series[:marker_shape]) else throw(ArgumentError("Plots(UnicodePlots): series type $st not supported")) end @@ -244,7 +244,7 @@ function addUnicodeSeries!( for (n, segment) in enumerate(series_segments(series, st; check = true)) i, rng = segment.attr_index, segment.range - lc = get_linecolor(series, i) + lc = get_line_color(series, i) up = func( up, x[rng], diff --git a/src/components.jl b/src/components.jl index 870cfb921..19447a7f8 100644 --- a/src/components.jl +++ b/src/components.jl @@ -551,7 +551,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) shapes[i] = scale(baseshape, msw * xscale / maxscale, msh * yscale / maxscale, (0, 0)) end - series[:markershape] = shapes + series[:marker_shape] = shapes series[:markersize] = msize end nothing @@ -833,3 +833,38 @@ end :match = ( :legend_title_font_family, :legend_title_font_color, ) + +### Line + +@add_attributes series struct Line + style = :solid + width = :auto + color = :auto + alpha = nothing +end + +### Marker + +@add_attributes series struct Marker + shape = :none + # color = :match + alpha = nothing + stroke::Line = Line(:solid, 1, :match, nothing) +end + +### Errorbars + +@add_attributes series struct XErrorBar + color = :match + shape = :hline + +end + +### Fills + +@add_attributes series struct YFill + range = nothing + color = :match + alpha = nothing + style = nothing +end diff --git a/src/consts.jl b/src/consts.jl index 764ac3c7a..85667b9df 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -42,7 +42,7 @@ const _internal_args = [ :plot_object, :series_plotindex, :series_index, - :markershape_to_add, + :marker_shape_to_add, :letter, :idxfilter, ] diff --git a/src/pipeline.jl b/src/pipeline.jl index 41a156fcb..2f62e38ff 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -356,11 +356,11 @@ function RecipesPipeline.add_series!(plt::Plot, plotattributes) sp = _prepare_subplot(plt, plotattributes) if (perm = plotattributes[:permute]) !== :none letter1, letter2 = perm - ms = plotattributes[:markershape] + ms = plotattributes[:marker_shape] if ms === :hline && (perm == (:x, :y) || perm == (:y, :x)) - plotattributes[:markershape] = :vline + plotattributes[:marker_shape] = :vline elseif ms === :vline && (perm == (:x, :y) || perm == (:y, :x)) - plotattributes[:markershape] = :hline + plotattributes[:marker_shape] = :hline end plotattributes[letter1], plotattributes[letter2] = plotattributes[letter2], plotattributes[letter1] diff --git a/src/recipes.jl b/src/recipes.jl index 4dbddd66d..06002adc3 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -46,19 +46,19 @@ RecipesBase.apply_recipe(plotattributes::AKW, ::Type{T}, plt::AbstractPlot) wher const POTENTIAL_VECTOR_ARGUMENTS = [ :seriescolor, :seriesalpha, - :linecolor, - :linealpha, - :linewidth, - :linestyle, + :line_color, + :line_alpha, + :line_width, + :line_style, :line_z, :fillcolor, :fillalpha, :fill_z, - :markercolor, - :markeralpha, - :markershape, + :marker_color, + :marker_alpha, + :marker_shape, :marker_z, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :xerror, :yerror, @@ -221,7 +221,7 @@ make_steps(t::Tuple, st, even) = Tuple(make_steps(ti, st, even) for ti in t) plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :pre, false) # create a secondary series for the markers - if plotattributes[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -246,7 +246,7 @@ end plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, true) # create a secondary series for the markers - if plotattributes[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -271,7 +271,7 @@ end plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, false) # create a secondary series for the markers - if plotattributes[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -319,7 +319,7 @@ end fillrange := nothing seriestype := :path if ( - plotattributes[:linecolor] === :auto && + plotattributes[:line_color] === :auto && plotattributes[:marker_z] !== nothing && plotattributes[:line_z] === nothing ) @@ -327,7 +327,7 @@ end end # create a primary series for the markers - if plotattributes[:markershape] !== :none + if plotattributes[:marker_shape] !== :none primary := false @series begin seriestype := :scatter @@ -677,7 +677,7 @@ end end # create a secondary series for the markers - if plotattributes[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := _bin_centers(edge) @@ -960,7 +960,7 @@ end @recipe function f(::Type{Val{:scatter3d}}, x, y, z) # COV_EXCL_LINE seriestype := :path3d - if plotattributes[:markershape] === :none + if plotattributes[:marker_shape] === :none markershape := :circle end linewidth := 0 @@ -999,12 +999,12 @@ export lens! series_plotindex := backup[:series_plotindex] seriestype := :path primary := false - linecolor := get(backup, :linecolor, :lightgray) - if haskey(backup, :linestyle) - linestyle := backup[:linestyle] + linecolor := get(backup, :line_color, :lightgray) + if haskey(backup, :line_style) + linestyle := backup[:line_style] end - if haskey(backup, :linewidth) - linewidth := backup[:linewidth] + if haskey(backup, :line_width) + linewidth := backup[:line_width] end bbx_mag = (x1 + x2) / 2 bby_mag = (y1 + y2) / 2 @@ -1083,11 +1083,11 @@ end haskey(plotattributes, :marker_z) && reset_kw!(plotattributes, :marker_z) haskey(plotattributes, :line_z) && reset_kw!(plotattributes, :line_z) - msc = if (msc = plotattributes[:markerstrokecolor]) === :match + msc = if (msc = plotattributes[:marker_stroke_color]) === :match plotattributes[:subplot][:foreground_color_subplot] elseif msc === :auto get_series_color( - plotattributes[:linecolor], + plotattributes[:line_color], plotattributes[:subplot], plotattributes[:series_plotindex], plotattributes[:seriestype], diff --git a/src/utils.jl b/src/utils.jl index aac8cc21a..e564e2dac 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -438,17 +438,17 @@ function contour_levels(series::Series, clims) levels end -for comp in (:line, :fill, :marker) +for comp in (:line_, :fill, :marker_) compcolor = string(comp, :color) get_compcolor = Symbol(:get_, compcolor) - comp_z = string(comp, :_z) + comp_z = string(comp, :z) compalpha = string(comp, :alpha) get_compalpha = Symbol(:get_, compalpha) @eval begin function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1) - c = series[$Symbol($compcolor)] # series[:linecolor], series[:fillcolor], series[:markercolor] + c = series[$Symbol($compcolor)] # series[:line_color], series[:fillcolor], series[:marker_color] z = series[$Symbol($comp_z)] # series[:line_z], series[:fill_z], series[:marker_z] if z === nothing isa(c, ColorGradient) ? c : plot_color(_cycle(c, i)) @@ -477,11 +477,11 @@ function get_colorgradient(series::Series) if st in (:surface, :heatmap) || isfilledcontour(series) series[:fillcolor] elseif st in (:contour, :wireframe) - series[:linecolor] + series[:line_color] elseif series[:marker_z] !== nothing - series[:markercolor] + series[:marker_color] elseif series[:line_z] !== nothing - series[:linecolor] + series[:line_color] elseif series[:fill_z] !== nothing series[:fillcolor] end @@ -494,12 +494,12 @@ get_gradient(c) = cgrad() get_gradient(cg::ColorGradient) = cg get_gradient(cp::ColorPalette) = cgrad(cp, categorical = true) -get_linewidth(series, i::Int = 1) = _cycle(series[:linewidth], i) -get_linestyle(series, i::Int = 1) = _cycle(series[:linestyle], i) +get_linewidth(series, i::Int = 1) = _cycle(series[:line_width], i) +get_linestyle(series, i::Int = 1) = _cycle(series[:line_style], i) get_fillstyle(series, i::Int = 1) = _cycle(series[:fillstyle], i) function get_markerstrokecolor(series, i::Int = 1) - msc = series[:markerstrokecolor] + msc = series[:marker_stroke_color] isa(msc, ColorGradient) ? msc : _cycle(msc, i) end @@ -509,20 +509,20 @@ get_markerstrokewidth(series, i::Int = 1) = _cycle(series[:markerstrokewidth], i const _segmenting_vector_attributes = ( :seriescolor, :seriesalpha, - :linecolor, - :linealpha, - :linewidth, - :linestyle, + :line_color, + :line_alpha, + :line_width, + :line_style, :fillcolor, :fillalpha, :fillstyle, - :markercolor, - :markeralpha, + :marker_color, + :marker_alpha, :markersize, - :markerstrokecolor, + :marker_stroke_color, :markerstrokealpha, :markerstrokewidth, - :markershape, + :marker_shape, ) const _segmenting_array_attributes = :line_z, :fill_z, :marker_z diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 95d0011b4..0e14f1ecc 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -86,9 +86,9 @@ with(:gr) do 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 + @test p[1][1][:line_style] == :solid + @test p[1][2][:line_style] == :dash + @test p[1][3][:line_style] == :dot end @testset "parametric" begin From d12b77020787fbcb92af7547c0ad3d93739be6c9 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Nov 2022 16:31:32 +0100 Subject: [PATCH 02/27] use kwdef in add_attributes --- src/args.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 770f02449..f8a84115b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -2182,6 +2182,7 @@ macro add_attributes(level, expr, match_table = :(:match = ())) end key_dict = KW() + original = copy(expr) _splitdef!(expr.args[3], key_dict) insert_block = Expr(:block) @@ -2212,7 +2213,7 @@ macro add_attributes(level, expr, match_table = :(:match = ())) ) end quote - $expr + Base.@kwdef $original $insert_block end |> esc end From 5dae3a365df9175053789f1ab41505b8da274ece Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Nov 2022 16:43:03 +0100 Subject: [PATCH 03/27] complete marker attributes --- NEWS.md | 2 +- src/arg_desc.jl | 8 ++--- src/args.jl | 26 +++++---------- src/backends.jl | 52 ++++++++++++++--------------- src/backends/deprecated/pgfplots.jl | 6 ++-- src/backends/gaston.jl | 2 +- src/backends/gr.jl | 8 ++--- src/backends/inspectdr.jl | 4 +-- src/backends/pgfplotsx.jl | 8 ++--- src/backends/plotly.jl | 10 +++--- src/backends/pyplot.jl | 4 +-- src/components.jl | 5 +-- src/recipes.jl | 4 +-- src/unitful.jl | 2 +- src/utils.jl | 10 +++--- 15 files changed, 72 insertions(+), 79 deletions(-) diff --git a/NEWS.md b/NEWS.md index fcb363c42..8e8d79d40 100644 --- a/NEWS.md +++ b/NEWS.md @@ -590,7 +590,7 @@ Many updates, min julia 1.0 - allow calling `plot!(sp, ...)` to update a target Subplot - PyPlot: zorder fix - new DataFrames logic/recipe: more flexible/robust and allow Symbols for: - - `(:fillrange, :line_z, :marker_z, :markersize, :ribbon, :weights, :xerror, :yerror)` + - `(:fillrange, :line_z, :marker_z, :marker_size, :ribbon, :weights, :xerror, :yerror)` - new `display_type` and `extra_kwargs` plot attributes - surface fix diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 0007561bd..f85d02d2d 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -17,11 +17,11 @@ const _arg_desc = KW( :fillstyle => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", :marker_color => "Color Type. Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`.", :marker_alpha => "Number in [0,1]. The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor.", - :markersize => "Number or AbstractVector. Size (radius pixels) of the markers", - :markerstrokestyle => "Symbol. Style of the marker stroke (border). Choose from $(_allStyles)", - :markerstrokewidth => "Number. Width of the marker stroke (border) in pixels", + :marker_size => "Number or AbstractVector. Size (radius pixels) of the markers", + :marker_stroke_style => "Symbol. Style of the marker stroke (border). Choose from $(_allStyles)", + :marker_stroke_width => "Number. Width of the marker stroke (border) in pixels", :marker_stroke_color => "Color Type. Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`.", - :markerstrokealpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.", + :marker_stroke_alpha => "Number in [0,1]. The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor.", :bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). For fine-grained control pass a Vector of break values, e.g. `range(minimum(x), stop = maximum(x), length = 25)`", :smooth => "Bool. Add a regression line?", :group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`", diff --git a/src/args.jl b/src/args.jl index f8a84115b..b3cd58f33 100644 --- a/src/args.jl +++ b/src/args.jl @@ -329,14 +329,6 @@ const _series_defaults = KW( :fillcolor => :match, :fillalpha => nothing, :fillstyle => nothing, - :marker_shape => :none, - :marker_color => :match, - :marker_alpha => nothing, - :markersize => 4, - :markerstrokestyle => :solid, - :markerstrokewidth => 1, - :marker_stroke_color => :match, - :markerstrokealpha => nothing, :bins => :auto, # number of bins for hists :smooth => false, # regression line? :group => nothing, # groupby vector @@ -612,7 +604,7 @@ add_aliases(:seriescolor, :c, :color, :colour) add_aliases(:line_color, :lc, :lcolor, :lcolour, :linecolour) add_aliases(:marker_color, :mc, :mcolor, :mcolour, :markercolour) add_aliases(:marker_stroke_color, :msc, :mscolor, :mscolour, :markerstrokecolour) -add_aliases(:markerstrokewidth, :msw, :mswidth) +add_aliases(:marker_stroke_width, :msw, :mswidth) add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) add_aliases( @@ -830,7 +822,7 @@ add_aliases( add_aliases(:seriesalpha, :alpha, :α, :opacity) add_aliases(:line_alpha, :la, :lalpha, :lα, :lineopacity, :lopacity) add_aliases(:marker_alpha, :ma, :malpha, :mα, :markeropacity, :mopacity) -add_aliases(:markerstrokealpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) +add_aliases(:marker_stroke_alpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) # axes attributes @@ -915,7 +907,7 @@ add_aliases(:line_width, :w, :width, :lw) add_aliases(:line_style, :style, :s, :ls) add_aliases(:marker, :m, :mark) add_aliases(:marker_shape, :shape) -add_aliases(:markersize, :ms, :msize) +add_aliases(:marker_size, :ms, :msize) add_aliases(:marker_z, :markerz, :zcolor, :mz) add_aliases(:line_z, :linez, :zline, :lz) add_aliases(:fill, :f, :area) @@ -1166,19 +1158,19 @@ function processMarkerArg(plotattributes::AKW, arg) # stroke style elseif allStyles(arg) - plotattributes[:markerstrokestyle] = arg + plotattributes[:marker_stroke_style] = arg elseif typeof(arg) <: Stroke - arg.width === nothing || (plotattributes[:markerstrokewidth] = arg.width) + arg.width === nothing || (plotattributes[:marker_stroke_width] = arg.width) arg.color === nothing || ( plotattributes[:marker_stroke_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:markerstrokealpha] = arg.alpha) - arg.style === nothing || (plotattributes[:markerstrokestyle] = arg.style) + arg.alpha === nothing || (plotattributes[:marker_stroke_alpha] = arg.alpha) + arg.style === nothing || (plotattributes[:marker_stroke_style] = arg.style) elseif typeof(arg) <: Brush - arg.size === nothing || (plotattributes[:markersize] = arg.size) + arg.size === nothing || (plotattributes[:marker_size] = arg.size) arg.color === nothing || ( plotattributes[:marker_color] = arg.color === :auto ? :auto : plot_color(arg.color) @@ -1195,7 +1187,7 @@ function processMarkerArg(plotattributes::AKW, arg) # markersize elseif allReals(arg) - plotattributes[:markersize] = arg + plotattributes[:marker_size] = arg # markercolor elseif !handleColors!(plotattributes, arg, :marker_color) diff --git a/src/backends.jl b/src/backends.jl index 73952b335..71cd5b129 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -310,11 +310,11 @@ const _gr_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, + :marker_stroke_alpha, :fillrange, :fillcolor, :fillalpha, @@ -442,12 +442,12 @@ const _plotly_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, - :markerstrokestyle, + :marker_stroke_alpha, + :marker_stroke_style, :fillrange, :fillcolor, :fillalpha, @@ -567,12 +567,12 @@ const _pgfplots_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, - :markerstrokestyle, + :marker_stroke_alpha, + :marker_stroke_style, :fillrange, :fillcolor, :fillalpha, @@ -682,11 +682,11 @@ const _pyplot_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, + :marker_stroke_alpha, :fillrange, :fillcolor, :fillalpha, @@ -803,9 +803,9 @@ const _gaston_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - # :markerstrokewidth, :marker_stroke_color, :markerstrokealpha, :markerstrokestyle, + # :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, # :fillrange, :fillcolor, :fillalpha, # :bins, # :bar_width, :bar_edges, @@ -983,11 +983,11 @@ const _hdf5_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, + :marker_stroke_alpha, :fillrange, :fillcolor, :fillalpha, @@ -1088,12 +1088,12 @@ const _inspectdr_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, - :markerstrokestyle, #Causes warning not to have it... what is this? + :marker_stroke_alpha, + :marker_stroke_style, #Causes warning not to have it... what is this? :fillcolor, :fillalpha, #:fillrange, # :bins, :bar_width, :bar_edges, :bar_position, @@ -1190,11 +1190,11 @@ const _pgfplotsx_attr = merge_with_base_supported([ :line_alpha, :marker_shape, :marker_color, - :markersize, + :marker_size, :marker_alpha, - :markerstrokewidth, + :marker_stroke_width, :marker_stroke_color, - :markerstrokealpha, + :marker_stroke_alpha, :fillrange, :fillcolor, :fillalpha, diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 04f6c08f9..780ecf748 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -131,14 +131,14 @@ function pgf_marker(plotattributes, i = 1) ) return string( "mark = $(get(_pgfplots_markers, shape, "*")),\n", - "mark size = $(pgf_thickness_scaling(plotattributes) * 0.5 * _cycle(plotattributes[:markersize], i)),\n", + "mark size = $(pgf_thickness_scaling(plotattributes) * 0.5 * _cycle(plotattributes[:marker_size], i)),\n", plotattributes[:seriestype] === :scatter ? "only marks,\n" : "", "mark options = { color = $cstr_stroke, draw opacity = $a_stroke, fill = $cstr, fill opacity = $a, - line width = $(pgf_thickness_scaling(plotattributes) * _cycle(plotattributes[:markerstrokewidth], i)), + line width = $(pgf_thickness_scaling(plotattributes) * _cycle(plotattributes[:marker_stroke_width], i)), rotate = $(shape === :dtriangle ? 180 : 0), - $(get(_pgfplots_linestyles, _cycle(plotattributes[:markerstrokestyle], i), "solid")) + $(get(_pgfplots_linestyles, _cycle(plotattributes[:marker_stroke_style], i), "solid")) }", ) end diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index 7558da604..b19ec5c84 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -527,7 +527,7 @@ gaston_lc_ls_lw(series::Series, clims, i::Int) = ( gaston_mk_ms_mc(series::Series, clims, i::Int) = ( gaston_marker(_cycle(series[:marker_shape], i), get_marker_alpha(series, i)), - _cycle(series[:markersize], i) * 1.3 / 5, + _cycle(series[:marker_size], i) * 1.3 / 5, gaston_color(get_marker_color(series, clims, i), get_marker_alpha(series, i)), ) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9fd96581d..3c44e911e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1041,8 +1041,8 @@ function gr_add_legend(sp, leg, viewport_area) end if (msh = series[:marker_shape]) !== :none - msz = first(series[:markersize]) - msw = first(series[:markerstrokewidth]) + msz = first(series[:marker_size]) + msw = first(series[:marker_stroke_width]) gr_draw_marker( series, xpos - 2leg.base_factor, @@ -1766,8 +1766,8 @@ function gr_draw_markers( y, z, clims, - msize = series[:markersize], - strokewidth = series[:markerstrokewidth], + msize = series[:marker_size], + strokewidth = series[:marker_stroke_width], ) isempty(x) && return GR.setfillintstyle(GR.INTSTYLE_SOLID) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 4f0e6f932..0411f3d38 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -302,11 +302,11 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) # InspectDR does not control markerstrokewidth independently. if _style === :none # Use this property only if no line is displayed: - wfrm.line.width = series[:markerstrokewidth] + wfrm.line.width = series[:marker_stroke_width] end wfrm.glyph = InspectDR.glyph( shape = _inspectdr_mapglyph(series[:marker_shape]), - size = _inspectdr_mapglyphsize(series[:markersize]), + size = _inspectdr_mapglyphsize(series[:marker_size]), color = _inspectdr_mapcolor( plot_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), ), diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 3de0c14d3..fcf95085f 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -341,7 +341,7 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o if opt[:marker_shape] !== :none if (marker = _cycle(opt[:marker_shape], i)) isa Shape scale_factor = 0.00125 - msize = opt[:markersize] * scale_factor + msize = opt[:marker_size] * scale_factor path = join( map((x, y) -> "($(x * msize), $(y * msize))", marker.x, marker.y), " -- ", @@ -935,7 +935,7 @@ function pgfx_marker(plotattributes, i = 1) mark_size = pgfx_thickness_scaling(plotattributes) * 0.75 * - _cycle(plotattributes[:markersize], i) + _cycle(plotattributes[:marker_size], i) mark_freq = if !any(isnan, plotattributes[:y]) && plotattributes[:marker_shape] isa AVec length(plotattributes[:marker_shape]) else @@ -953,7 +953,7 @@ function pgfx_marker(plotattributes, i = 1) "line width" => pgfx_thickness_scaling(plotattributes) * 0.75 * - _cycle(plotattributes[:markerstrokewidth], i), + _cycle(plotattributes[:marker_stroke_width], i), "rotate" => if shape === :dtriangle 180 elseif shape === :rtriangle @@ -963,7 +963,7 @@ function pgfx_marker(plotattributes, i = 1) else 0 end, - pgfx_get_linestyle(_cycle(plotattributes[:markerstrokestyle], i)) => + pgfx_get_linestyle(_cycle(plotattributes[:marker_stroke_style], i)) => nothing, ), ) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 1c4cbbc7f..eff913e5d 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -681,7 +681,7 @@ function plotly_series(plt::Plot, series::Series) :symbol => get_plotly_marker(series[:marker_shape], string(series[:marker_shape])), # :opacity => series[:marker_alpha], - :size => 2_cycle(series[:markersize], inds), + :size => 2_cycle(series[:marker_size], inds), :color => rgba_string.( plot_color.( @@ -697,7 +697,7 @@ function plotly_series(plt::Plot, series::Series) get_markerstrokealpha.(series, inds), ), ), - :width => _cycle(series[:markerstrokewidth], inds), + :width => _cycle(series[:marker_stroke_width], inds), ), ) end @@ -747,7 +747,7 @@ function plotly_series_shapes(plt::Plot, series::Series, clims) ), ), ) - if series[:markerstrokewidth] > 0 + if series[:marker_stroke_width] > 0 plotattributes_out[:line] = KW( :color => rgba_string( plot_color(get_line_color(series, clims, i), get_line_alpha(series, i)), @@ -863,11 +863,11 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z string(_cycle(series[:marker_shape], i)), ), # :opacity => needs_scatter_fix ? [1, 0] : 1, - :size => 2_cycle(series[:markersize], i), + :size => 2_cycle(series[:marker_size], i), :color => needs_scatter_fix ? [mcolor, mcolor_next] : mcolor, :line => KW( :color => needs_scatter_fix ? [lcolor, lcolor_next] : lcolor, - :width => _cycle(series[:markerstrokewidth], i), + :width => _cycle(series[:marker_stroke_width], i), ), ) end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 76a5bb194..b06445550 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -510,7 +510,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = series[:label], zorder = series[:series_plotindex] + 0.5, marker = py_marker(_cycle(series[:marker_shape], i)), - s = py_thickness_scale(plt, _cycle(series[:markersize], i)) .^ 2, + s = py_thickness_scale(plt, _cycle(series[:marker_size], i)) .^ 2, facecolors = py_color( get_marker_color(series, i), get_marker_alpha(series, i), @@ -1533,7 +1533,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) markeredgewidth = py_thickness_scale( plt, 0.8get_markerstrokewidth(series) * sp[:legend_font_pointsize] / - first(series[:markersize]), + first(series[:marker_size]), ), # retain the markersize/markerstroke ratio from the markers on the plot ) push!(handles, handle) diff --git a/src/components.jl b/src/components.jl index 19447a7f8..600acd5a4 100644 --- a/src/components.jl +++ b/src/components.jl @@ -552,7 +552,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) scale(baseshape, msw * xscale / maxscale, msh * yscale / maxscale, (0, 0)) end series[:marker_shape] = shapes - series[:markersize] = msize + series[:marker_size] = msize end nothing end @@ -847,9 +847,10 @@ end @add_attributes series struct Marker shape = :none - # color = :match + color = :match alpha = nothing stroke::Line = Line(:solid, 1, :match, nothing) + size = 4 end ### Errorbars diff --git a/src/recipes.jl b/src/recipes.jl index 06002adc3..7ba13c8d5 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -59,7 +59,7 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ :marker_shape, :marker_z, :marker_stroke_color, - :markerstrokealpha, + :marker_stroke_alpha, :xerror, :yerror, :zerror, @@ -1100,7 +1100,7 @@ end markerstrokecolor --> msc markercolor --> msc linecolor --> msc - linewidth --> plotattributes[:markerstrokewidth] + linewidth --> plotattributes[:marker_stroke_width] label --> "" end diff --git a/src/unitful.jl b/src/unitful.jl index ae483bd99..e5552b5d5 100644 --- a/src/unitful.jl +++ b/src/unitful.jl @@ -155,7 +155,7 @@ function fixmarkercolor!(attr) ustripattribute!(attr, :clims, u) u == Unitful.NoUnits || append_unit_if_needed!(attr, :colorbar_title, u) end -fixmarkersize!(attr) = ustripattribute!(attr, :markersize) +fixmarkersize!(attr) = ustripattribute!(attr, :marker_size) fixlinecolor!(attr) = ustripattribute!(attr, :line_z) # strip unit from attribute[key] diff --git a/src/utils.jl b/src/utils.jl index e564e2dac..29467dccb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -503,8 +503,8 @@ function get_markerstrokecolor(series, i::Int = 1) isa(msc, ColorGradient) ? msc : _cycle(msc, i) end -get_markerstrokealpha(series, i::Int = 1) = _cycle(series[:markerstrokealpha], i) -get_markerstrokewidth(series, i::Int = 1) = _cycle(series[:markerstrokewidth], i) +get_markerstrokealpha(series, i::Int = 1) = _cycle(series[:marker_stroke_alpha], i) +get_markerstrokewidth(series, i::Int = 1) = _cycle(series[:marker_stroke_width], i) const _segmenting_vector_attributes = ( :seriescolor, @@ -518,10 +518,10 @@ const _segmenting_vector_attributes = ( :fillstyle, :marker_color, :marker_alpha, - :markersize, + :marker_size, :marker_stroke_color, - :markerstrokealpha, - :markerstrokewidth, + :marker_stroke_alpha, + :marker_stroke_width, :marker_shape, ) From 69e839a926a4b0101c65df2d7a684e1f820aeebb Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Nov 2022 17:17:14 +0100 Subject: [PATCH 04/27] rename yfill -> fill --- NEWS.md | 4 +- RecipesPipeline/src/series_recipe.jl | 2 +- src/arg_desc.jl | 8 ++-- src/args.jl | 48 +++++++++++------------- src/axes.jl | 4 +- src/backends.jl | 46 +++++++++++------------ src/backends/deprecated/pgfplots.jl | 10 ++--- src/backends/gaston.jl | 4 +- src/backends/gr.jl | 22 +++++------ src/backends/inspectdr.jl | 2 +- src/backends/pgfplotsx.jl | 4 +- src/backends/plotly.jl | 56 ++++++++++++++-------------- src/backends/pyplot.jl | 20 +++++----- src/pipeline.jl | 6 +-- src/recipes.jl | 26 ++++++------- src/unitful.jl | 2 +- src/utils.jl | 22 +++++------ test/test_defaults.jl | 4 +- test/test_misc.jl | 4 +- 19 files changed, 145 insertions(+), 149 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8e8d79d40..8eb76b21e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -590,7 +590,7 @@ Many updates, min julia 1.0 - allow calling `plot!(sp, ...)` to update a target Subplot - PyPlot: zorder fix - new DataFrames logic/recipe: more flexible/robust and allow Symbols for: - - `(:fillrange, :line_z, :marker_z, :marker_size, :ribbon, :weights, :xerror, :yerror)` + - `(:yfill_range, :line_z, :marker_z, :marker_size, :ribbon, :weights, :xerror, :yerror)` - new `display_type` and `extra_kwargs` plot attributes - surface fix @@ -808,7 +808,7 @@ Many updates, min julia 1.0 - New dependency on Requires, allows auto-loading of DataFrames support - Support for plotting lists of Tuples and FixedSizeArrays - new `@animate` macro for super simple animations (see https://github.com/tbreloff/Plots.jl/issues/111#issuecomment-181515616) -- allow Function for `:fillrange` and `zcolor` arguments (for example: `scatter(sin, 0:10, marker=15, fill=(cos,0.4), zcolor=sin)`) +- allow Function for `:yfill_range` and `zcolor` arguments (for example: `scatter(sin, 0:10, marker=15, fill=(cos,0.4), zcolor=sin)`) - allow vectors of PlotText without x/y coords (for example: `scatter(rand(10), m=20, ann=map(text, 1:10))`) - Lots and lots of fixes diff --git a/RecipesPipeline/src/series_recipe.jl b/RecipesPipeline/src/series_recipe.jl index bb4275803..8f8cdc9bc 100644 --- a/RecipesPipeline/src/series_recipe.jl +++ b/RecipesPipeline/src/series_recipe.jl @@ -37,7 +37,7 @@ function _process_seriesrecipe(plt, plotattributes) # shapes shouldn't have fillrange set if plotattributes[:seriestype] == :shape - plotattributes[:fillrange] = nothing + plotattributes[:yfill_range] = nothing end # if it's natively supported, finalize processing and pass along to the backend, diff --git a/src/arg_desc.jl b/src/arg_desc.jl index f85d02d2d..a62cba8f6 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -10,11 +10,11 @@ const _arg_desc = KW( :line_width => "Number. Width of the line (in pixels)", :line_color => "Color Type. Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default).", :line_alpha => "Number in [0,1]. The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor.", - :fillrange => "Number or AbstractVector. Fills area between fillrange and y for line-types, sets the base for bar/stick types, and similar for other types.", - :fillcolor => "Color Type. Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`.", - :fillalpha => "Number in [0,1]. The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor.", + :yfill_range => "Number or AbstractVector. Fills area between fillrange and y for line-types, sets the base for bar/stick types, and similar for other types.", + :yfill_color => "Color Type. Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`.", + :yfill_alpha => "Number in [0,1]. The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor.", :marker_shape => "Symbol, Shape, or AbstractVector. Choose from $(_allMarkers).", - :fillstyle => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", + :yfill_style => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", :marker_color => "Color Type. Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`.", :marker_alpha => "Number in [0,1]. The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor.", :marker_size => "Number or AbstractVector. Size (radius pixels) of the markers", diff --git a/src/args.jl b/src/args.jl index b3cd58f33..04156bbf4 100644 --- a/src/args.jl +++ b/src/args.jl @@ -325,10 +325,6 @@ const _series_defaults = KW( :seriescolor => :auto, :seriesalpha => nothing, :seriestype => :path, - :fillrange => nothing, # ribbons, areas, etc - :fillcolor => :match, - :fillalpha => nothing, - :fillstyle => nothing, :bins => :auto, # number of bins for hists :smooth => false, # regression line? :group => nothing, # groupby vector @@ -605,7 +601,7 @@ add_aliases(:line_color, :lc, :lcolor, :lcolour, :linecolour) add_aliases(:marker_color, :mc, :mcolor, :mcolour, :markercolour) add_aliases(:marker_stroke_color, :msc, :mscolor, :mscolour, :markerstrokecolour) add_aliases(:marker_stroke_width, :msw, :mswidth) -add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) +add_aliases(:yfill_color, :fc, :fcolor, :fcolour, :fillcolour) add_aliases( :background_color, @@ -823,7 +819,7 @@ add_aliases(:seriesalpha, :alpha, :α, :opacity) add_aliases(:line_alpha, :la, :lalpha, :lα, :lineopacity, :lopacity) add_aliases(:marker_alpha, :ma, :malpha, :mα, :markeropacity, :mopacity) add_aliases(:marker_stroke_alpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) -add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) +add_aliases(:yfill_alpha, :fa, :falpha, :fα, :fillopacity, :fopacity) # axes attributes add_axes_aliases(:guide, :label, :lab, :l; generic = false) @@ -911,7 +907,7 @@ add_aliases(:marker_size, :ms, :msize) add_aliases(:marker_z, :markerz, :zcolor, :mz) add_aliases(:line_z, :linez, :zline, :lz) add_aliases(:fill, :f, :area) -add_aliases(:fillrange, :fillrng, :frange, :fillto, :fill_between) +add_aliases(:yfill_range, :fillrng, :frange, :fillto, :fill_between) add_aliases(:group, :g, :grouping) add_aliases(:bins, :bin, :nbin, :nbins, :nb) add_aliases(:ribbon, :rib) @@ -1126,13 +1122,13 @@ function processLineArg(plotattributes::AKW, arg) arg.style === nothing || (plotattributes[:line_style] = arg.style) elseif typeof(arg) <: Brush - arg.size === nothing || (plotattributes[:fillrange] = arg.size) + arg.size === nothing || (plotattributes[:yfill_range] = arg.size) arg.color === nothing || ( - plotattributes[:fillcolor] = + plotattributes[:yfill_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:fillalpha] = arg.alpha) - arg.style === nothing || (plotattributes[:fillstyle] = arg.style) + arg.alpha === nothing || (plotattributes[:yfill_alpha] = arg.alpha) + arg.style === nothing || (plotattributes[:yfill_style] = arg.style) elseif typeof(arg) <: Arrow || arg in (:arrow, :arrows) plotattributes[:arrow] = arg @@ -1196,35 +1192,35 @@ function processMarkerArg(plotattributes::AKW, arg) end function processFillArg(plotattributes::AKW, arg) - # fr = get(plotattributes, :fillrange, 0) + # fr = get(plotattributes, :yfill_range, 0) if typeof(arg) <: Brush - arg.size === nothing || (plotattributes[:fillrange] = arg.size) + arg.size === nothing || (plotattributes[:yfill_range] = arg.size) arg.color === nothing || ( - plotattributes[:fillcolor] = + plotattributes[:yfill_color] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:fillalpha] = arg.alpha) - arg.style === nothing || (plotattributes[:fillstyle] = arg.style) + arg.alpha === nothing || (plotattributes[:yfill_alpha] = arg.alpha) + arg.style === nothing || (plotattributes[:yfill_style] = arg.style) elseif typeof(arg) <: Bool - plotattributes[:fillrange] = arg ? 0 : nothing + plotattributes[:yfill_range] = arg ? 0 : nothing # fillrange function elseif allFunctions(arg) - plotattributes[:fillrange] = arg + plotattributes[:yfill_range] = arg # fillalpha elseif allAlphas(arg) - plotattributes[:fillalpha] = arg + plotattributes[:yfill_alpha] = arg # fillrange provided as vector or number elseif typeof(arg) <: Union{AbstractArray{<:Real},Real} - plotattributes[:fillrange] = arg + plotattributes[:yfill_range] = arg - elseif !handleColors!(plotattributes, arg, :fillcolor) - plotattributes[:fillrange] = arg + elseif !handleColors!(plotattributes, arg, :yfill_color) + plotattributes[:yfill_range] = arg end - # plotattributes[:fillrange] = fr + # plotattributes[:yfill_range] = fr nothing end @@ -2081,7 +2077,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) ) # update alphas - for asym in (:line_alpha, :marker_alpha, :fillalpha) + for asym in (:line_alpha, :marker_alpha, :yfill_alpha) if plotattributes[asym] === nothing plotattributes[asym] = plotattributes[:seriesalpha] end @@ -2096,7 +2092,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) plotattributes[:seriescolor] = scolor = get_series_color(scolor, sp, plotIndex, stype) # update other colors - for s in (:line_, :marker_, :fill) + for s in (:line_, :marker_, :yfill_) csym, asym = Symbol(s, :color), Symbol(s, :alpha) plotattributes[csym] = if plotattributes[csym] === :auto plot_color(if has_black_border_for_default(stype) && s === :line @@ -2128,7 +2124,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) ensure_gradient!(plotattributes, :line_color, :line_alpha) end if plotattributes[:fill_z] !== nothing - ensure_gradient!(plotattributes, :fillcolor, :fillalpha) + ensure_gradient!(plotattributes, :yfill_color, :yfill_alpha) end # scatter plots don't have a line, but must have a shape diff --git a/src/axes.jl b/src/axes.jl index 3f6470aa7..c04fb30d5 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -453,7 +453,7 @@ function expand_extrema!(sp::Subplot, plotattributes::AKW) # end # expand for fillrange - fr = plotattributes[:fillrange] + fr = plotattributes[:yfill_range] if fr === nothing && plotattributes[:seriestype] === :bar fr = 0.0 end @@ -512,7 +512,7 @@ end scale_lims!([plt], [letter], factor) Scale the limits of the axis specified by `letter` (one of `:x`, `:y`, `:z`) by the -given `factor` around the limits' middle point. +given `factor` around the limits' middle point. If `letter` is omitted, all axes are affected. """ function scale_lims!(sp::Subplot, letter, factor) diff --git a/src/backends.jl b/src/backends.jl index 71cd5b129..4bccaf0ba 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -315,10 +315,10 @@ const _gr_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :fillrange, - :fillcolor, - :fillalpha, - :fillstyle, + :yfill_range, + :yfill_color, + :yfill_alpha, + :yfill_style, :bins, :layout, :title, @@ -448,9 +448,9 @@ const _plotly_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - :fillrange, - :fillcolor, - :fillalpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :title, :titlelocation, @@ -573,9 +573,9 @@ const _pgfplots_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - :fillrange, - :fillcolor, - :fillalpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, # :bar_width, :bar_edges, :title, @@ -687,10 +687,10 @@ const _pyplot_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :fillrange, - :fillcolor, - :fillalpha, - :fillstyle, + :yfill_range, + :yfill_color, + :yfill_alpha, + :yfill_style, :bins, :bar_width, :bar_edges, @@ -806,7 +806,7 @@ const _gaston_attr = merge_with_base_supported([ :marker_size, :marker_alpha, # :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - # :fillrange, :fillcolor, :fillalpha, + # :yfill_range, :yfill_color, :yfill_alpha, # :bins, # :bar_width, :bar_edges, :title, @@ -988,9 +988,9 @@ const _hdf5_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :fillrange, - :fillcolor, - :fillalpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :bar_width, :bar_edges, @@ -1094,8 +1094,8 @@ const _inspectdr_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, #Causes warning not to have it... what is this? - :fillcolor, - :fillalpha, #:fillrange, + :yfill_color, + :yfill_alpha, #:yfill_range, # :bins, :bar_width, :bar_edges, :bar_position, :title, :titlelocation, @@ -1195,9 +1195,9 @@ const _pgfplotsx_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :fillrange, - :fillcolor, - :fillalpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :layout, :title, diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 780ecf748..2c241a63a 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -225,12 +225,12 @@ function pgf_series(sp::Subplot, series::Series) # add to legend? if i == 1 && sp[:legend_position] !== :none && should_add_to_legend(series) - if plotattributes[:fillrange] !== nothing + if plotattributes[:yfill_range] !== nothing push!(style, "forget plot") push!(series_collection, pgf_fill_legend_hack(plotattributes, args)) else kw[:legendentry] = plotattributes[:label] - if st === :shape # || plotattributes[:fillrange] !== nothing + if st === :shape # || plotattributes[:yfill_range] !== nothing push!(style, "area legend") end end @@ -247,13 +247,13 @@ function pgf_series(sp::Subplot, series::Series) kw[:style] = join(style, ',') # add fillrange - if series[:fillrange] !== nothing && st !== :shape + if series[:yfill_range] !== nothing && st !== :shape push!( series_collection, pgf_fillrange_series( series, i, - _cycle(series[:fillrange], rng), + _cycle(series[:yfill_range], rng), seg_args..., ), ) @@ -641,7 +641,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # As it is likely that all series within the same axis use the same # colormap this should not cause any problem. for series in series_list(sp) - for col in (:marker_color, :fillcolor, :line_color) + for col in (:marker_color, :yfill_color, :line_color) if typeof(series.plotattributes[col]) == ColorGradient push!( style, diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index b19ec5c84..955723721 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -219,7 +219,7 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series) if gsp.dims == 2 && z === nothing for (n, seg) in enumerate(series_segments(series, st; check = true)) i, rng = seg.attr_index, seg.range - fr = _cycle(series[:fillrange], 1:length(x[rng])) + fr = _cycle(series[:yfill_range], 1:length(x[rng])) for sc in gaston_seriesconf!(sp, series, i, n == 1) push!(curves, Gaston.Curve(x[rng], y[rng], nothing, fr, sc)) end @@ -293,7 +293,7 @@ function gaston_seriesconf!( pt, ps, mc = gaston_mk_ms_mc(series, clims, i) push!(curveconf, "w points pt $pt ps $ps lc $mc") elseif st ∈ (:path, :straightline, :path3d) - fr = series[:fillrange] + fr = series[:yfill_range] fc = gaston_color(get_fillcolor(series, i), get_fillalpha(series, i)) fs = get_fillstyle(series, i) # FIXME: add fillstyle support ? lc, dt, lw = gaston_lc_ls_lw(series, clims, i) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 3c44e911e..89296cf26 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1010,7 +1010,7 @@ function gr_add_legend(sp, leg, viewport_area) _debugMode[] && gr_legend_bbox(xpos, ypos, leg) if ( - (st === :shape || series[:fillrange] !== nothing) && + (st === :shape || series[:yfill_range] !== nothing) && series[:ribbon] === nothing ) (fc = get_fillcolor(series, clims)) |> gr_set_fill @@ -1035,7 +1035,7 @@ function gr_add_legend(sp, leg, viewport_area) max_markersize = Inf if st in (:path, :straightline, :path3d) max_markersize = leg.base_markersize - gr_set_transparency(lc, get_linealpha(series)) + gr_set_transparency(lc, get_line_alpha(series)) filled = series[:fillrange] !== nothing && series[:ribbon] === nothing GR.polyline(xpos .+ [lft, rgt], ypos .+ (filled ? [top, top] : [0, 0])) end @@ -1649,7 +1649,7 @@ function gr_add_series(sp, series) x, y, z = map(letter -> handle_surface(series[letter]), (:x, :y, :z)) xscale, yscale = sp[:xaxis][:scale], sp[:yaxis][:scale] - frng = series[:fillrange] + frng = series[:yfill_range] # recompute data if ispolar(sp) && z === nothing @@ -1829,7 +1829,7 @@ function gr_draw_contour(series, x, y, z, clims) gr_set_line(get_linewidth(series), get_linestyle(series), get_line_color(series), series) gr_set_transparency(get_fillalpha(series)) h = gr_contour_levels(series, clims) - if series[:fillrange] !== nothing + if series[:yfill_range] !== nothing GR.contourf(x, y, h, z, series[:contour_labels] == true ? 1 : 0) else black = plot_color(:black) @@ -1885,10 +1885,10 @@ function gr_draw_surface(series, x, y, z, clims) ArgumentError |> throw end - facecolor = if series[:fillcolor] isa AbstractArray - series[:fillcolor] + facecolor = if series[:yfill_color] isa AbstractArray + series[:yfill_color] else - fill(series[:fillcolor], length(cns)) + fill(series[:yfill_color], length(cns)) end fillalpha = get_fillalpha(series) facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor) @@ -1902,7 +1902,7 @@ function gr_draw_surface(series, x, y, z, clims) end function gr_draw_heatmap(series, x, y, z, clims) - fillgrad = _as_gradient(series[:fillcolor]) + fillgrad = _as_gradient(series[:yfill_color]) GR.setprojectiontype(0) GR.setspace(clims..., 0, 90) w, h = length(x) - 1, length(y) - 1 @@ -1914,18 +1914,18 @@ function gr_draw_heatmap(series, x, y, z, clims) # Note that drawimage draws uniformly spaced data correctly # even on log scales, where it is visually non-uniform. colors, _z = if sp[:colorbar_scale] === :identity - plot_color.(get(fillgrad, z, clims), series[:fillalpha]), z + plot_color.(get(fillgrad, z, clims), series[:yfill_alpha]), z elseif sp[:colorbar_scale] === :log10 z_log = replace(x -> isinf(x) ? NaN : x, log10.(z)) z_normalized = get_z_normalized.(z_log, log10.(clims)...) - plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:fillalpha]), z_log + plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:yfill_alpha]), z_log end for i in eachindex(colors) isnan(_z[i]) && (colors[i] = set_RGBA_alpha(0, colors[i])) end GR.drawimage(first(x), last(x), last(y), first(y), w, h, gr_color.(colors)) else - if something(series[:fillalpha], 1) < 1 + if something(series[:yfill_alpha], 1) < 1 @warn "GR: transparency not supported in non-uniform heatmaps. Alpha values ignored." end z_normalized, _z = if sp[:colorbar_scale] === :identity diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 0411f3d38..21cf8bc3b 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -240,7 +240,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) end #= TODO: Eventually support - series[:fillcolor] #I think this is fill under line + series[:yfill_color] #I think this is fill under line zorder = series[:series_plotindex] For st in :shape: diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index fcf95085f..c04fd5f70 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -283,7 +283,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) PGFPlotsX.Plot end if ( - series[:fillrange] !== nothing && + series[:yfill_range] !== nothing && series[:ribbon] === nothing && !isfilledcontour(series) ) @@ -359,7 +359,7 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o segment_opt = merge(segment_opt, pgfx_marker(opt, i)) end # add fillrange - if (sf = opt[:fillrange]) !== nothing && !isfilledcontour(series) + if (sf = opt[:yfill_range]) !== nothing && !isfilledcontour(series) if sf isa Number || sf isa AVec pgfx_fillrange_series!(axis, series, series_func, i, _cycle(sf, rng), rng) elseif sf isa Tuple && series[:ribbon] !== nothing diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index eff913e5d..dd20dfc7c 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -544,7 +544,7 @@ function plotly_series(plt::Plot, series::Series) hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && - (isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple)) + (isa(series[:yfill_range], AbstractVector) || isa(series[:yfill_range], Tuple)) plotattributes_out[:colorbar] = KW(:title => sp[:colorbar_title]) @@ -562,7 +562,7 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:type] = "heatmap" plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z plotattributes_out[:colorscale] = - plotly_colorscale(series[:fillcolor], series[:fillalpha]) + plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) plotattributes_out[:showscale] = hascolorbar(sp) elseif st === :contour @@ -617,8 +617,8 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:showscale] = false else plotattributes_out[:colorscale] = - plotly_colorscale(series[:fillcolor], series[:fillalpha]) - plotattributes_out[:opacity] = series[:fillalpha] + plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) + plotattributes_out[:opacity] = series[:yfill_alpha] if series[:fill_z] !== nothing plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z]) end @@ -661,10 +661,10 @@ function plotly_series(plt::Plot, series::Series) end end plotattributes_out[:colorscale] = - plotly_colorscale(series[:fillcolor], series[:fillalpha]) + plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) plotattributes_out[:color] = - rgba_string(plot_color(series[:fillcolor], series[:fillalpha])) - plotattributes_out[:opacity] = series[:fillalpha] + rgba_string(plot_color(series[:yfill_color], series[:yfill_alpha])) + plotattributes_out[:opacity] = series[:yfill_alpha] if series[:fill_z] !== nothing plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z]) end @@ -742,7 +742,7 @@ function plotly_series_shapes(plt::Plot, series::Series, clims) :x => vcat(x[rng], x[rng[1]]), :y => vcat(y[rng], y[rng[1]]), :fill => "tozeroy", - :fillcolor => rgba_string( + :yfill_color => rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ), ), @@ -782,7 +782,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && - (isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple)) + (isa(series[:yfill_range], AbstractVector) || isa(series[:yfill_range], Tuple)) segments = collect(series_segments(series, st)) plotattributes_outs = fill(KW(), (hasfillrange ? 2 : 1) * length(segments)) @@ -804,20 +804,20 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z else hasline ? "lines" : "none" end - if series[:fillrange] == true || - series[:fillrange] == 0 || - isa(series[:fillrange], Tuple) + if series[:yfill_range] == true || + series[:yfill_range] == 0 || + isa(series[:yfill_range], Tuple) plotattributes_out[:fill] = "tozeroy" - plotattributes_out[:fillcolor] = rgba_string( + plotattributes_out[:yfill_color] = rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ) - elseif typeof(series[:fillrange]) <: Union{AbstractVector{<:Real},Real} + elseif typeof(series[:yfill_range]) <: Union{AbstractVector{<:Real},Real} plotattributes_out[:fill] = "tonexty" - plotattributes_out[:fillcolor] = rgba_string( + plotattributes_out[:yfill_color] = rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ) - elseif !(series[:fillrange] in (false, nothing)) - @warn "fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])" + elseif !(series[:yfill_range] in (false, nothing)) + @warn "fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:yfill_range])" end plotattributes_out[:x], plotattributes_out[:y] = x[rng], y[rng] @@ -901,29 +901,29 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z plotattributes_out_fillrange = deepcopy(plotattributes_out) plotattributes_out_fillrange[:showlegend] = false # if fillrange is provided as real or tuple of real, expand to array - if typeof(series[:fillrange]) <: Real - plotattributes_out[:fillrange] = fill(series[:fillrange], length(rng)) - elseif typeof(series[:fillrange]) <: Tuple + if typeof(series[:yfill_range]) <: Real + plotattributes_out[:yfill_range] = fill(series[:yfill_range], length(rng)) + elseif typeof(series[:yfill_range]) <: Tuple f1 = - (fr1 = series[:fillrange][1]) |> typeof <: Real ? + (fr1 = series[:yfill_range][1]) |> typeof <: Real ? fill(fr1, length(rng)) : fr1[rng] f2 = - (fr2 = series[:fillrange][2]) |> typeof <: Real ? + (fr2 = series[:yfill_range][2]) |> typeof <: Real ? fill(fr2, length(rng)) : fr2[rng] - plotattributes_out[:fillrange] = (f1, f2) + plotattributes_out[:yfill_range] = (f1, f2) end - if isa(series[:fillrange], AbstractVector) - plotattributes_out_fillrange[:y] = series[:fillrange][rng] + if isa(series[:yfill_range], AbstractVector) + plotattributes_out_fillrange[:y] = series[:yfill_range][rng] delete!(plotattributes_out_fillrange, :fill) - delete!(plotattributes_out_fillrange, :fillcolor) + delete!(plotattributes_out_fillrange, :yfill_color) else # if fillrange is a tuple with upper and lower limit, plotattributes_out_fillrange # is the series that will do the filling plotattributes_out_fillrange[:x], plotattributes_out_fillrange[:y] = - concatenate_fillrange(x[rng], series[:fillrange]) + concatenate_fillrange(x[rng], series[:yfill_range]) plotattributes_out_fillrange[:line][:width] = 0 delete!(plotattributes_out, :fill) - delete!(plotattributes_out, :fillcolor) + delete!(plotattributes_out, :yfill_color) end plotattributes_outs[(2k - 1):(2k)] = diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index b06445550..8bbcc1f7a 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -246,7 +246,7 @@ py_linecolormap(series::Series) = py_markercolormap(series::Series) = py_colormap(cgrad(series[:marker_color], alpha = get_marker_alpha(series))) py_fillcolormap(series::Series) = - py_colormap(cgrad(series[:fillcolor], alpha = get_fillalpha(series))) + py_colormap(cgrad(series[:yfill_color], alpha = get_fillalpha(series))) # --------------------------------------------------------------------------- @@ -537,7 +537,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) C = series[:weights], gridsize = series[:bins] === :auto ? 100 : series[:bins], # 100 is the default value linewidths = py_thickness_scale(plt, series[:line_width]), - alpha = series[:fillalpha], + alpha = series[:yfill_alpha], cmap = py_fillcolormap(series), # applies to the pcolorfast object zorder = series[:series_plotindex], extrakw..., @@ -577,7 +577,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) push!(handles, handle) # contour fills - if series[:fillrange] !== nothing + if series[:yfill_range] !== nothing handle = ax."contourf"( x, y, @@ -585,7 +585,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) levelargs...; label = series[:label], zorder = series[:series_plotindex] + 0.5, - alpha = series[:fillalpha], + alpha = series[:yfill_alpha], extrakw..., ) push!(handles, handle) @@ -601,7 +601,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) if series[:fill_z] !== nothing # the surface colors are different than z-value extrakw[:facecolors] = - py_shading(series[:fillcolor], py_handle_surface(series[:fill_z])) + py_shading(series[:yfill_color], py_handle_surface(series[:fill_z])) extrakw[:shade] = false else extrakw[:cmap] = py_fillcolormap(series) @@ -685,14 +685,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) polygons, linewidths = py_thickness_scale(plt, series[:line_width]), edgecolor = py_color(get_line_color(series)), - facecolor = py_color(series[:fillcolor]), + facecolor = py_color(series[:yfill_color]), alpha = get_fillalpha(series), zorder = series[:series_plotindex], ) handle = ax."add_collection3d"(col) # Fix for handle: https://stackoverflow.com/questions/54994600/pyplot-legend-poly3dcollection-object-has-no-attribute-edgecolors2d # It seems there aren't two different alpha values for edge and face - handle._facecolors2d = py_color(series[:fillcolor]) + handle._facecolors2d = py_color(series[:yfill_color]) handle._edgecolors2d = py_color(get_line_color(series)) push!(handles, handle) end @@ -740,7 +740,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = series[:label], zorder = series[:series_plotindex], cmap = py_fillcolormap(series), - alpha = series[:fillalpha], + alpha = series[:yfill_alpha], # edgecolors = (series[:line_width] > 0 ? py_linecolor(series) : "face"), extrakw..., ) @@ -802,7 +802,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # handleSmooth(plt, ax, series, series[:smooth]) # handle area filling - fillrange = series[:fillrange] + fillrange = series[:yfill_range] if fillrange !== nothing && st !== :contour for segment in series_segments(series) i, rng = segment.attr_index, segment.range @@ -1466,7 +1466,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) nseries += 1 clims = get_clims(sp, series) # add a line/marker and a label - if series[:seriestype] === :shape || series[:fillrange] !== nothing + if series[:seriestype] === :shape || series[:yfill_range] !== nothing lc = get_line_color(series, clims) fc = get_fillcolor(series, clims) la = get_line_alpha(series) diff --git a/src/pipeline.jl b/src/pipeline.jl index 2f62e38ff..ced8c383f 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -127,7 +127,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::AKW) :seriestype => :path, :x => sx, :y => sy, - :fillrange => nothing, + :yfill_range => nothing, :label => "", :primary => false, ), @@ -176,7 +176,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l kw[:z_extrema] = ze rib = get(kw, :ribbon, default(:ribbon)) - fr = get(kw, :fillrange, default(:fillrange)) + fr = get(kw, :yfill_range, default(:yfill_range)) # map ribbon if it's a Function if rib isa Function kw[:ribbon] = map(rib, kw[:x]) @@ -186,7 +186,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l make_fillrange_from_ribbon(kw) # map fillrange if it's a Function elseif fr !== nothing && fr isa Function - kw[:fillrange] = map(fr, kw[:x]) + kw[:yfill_range] = map(fr, kw[:x]) end end nothing diff --git a/src/recipes.jl b/src/recipes.jl index 7ba13c8d5..4ee9b6c01 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -51,8 +51,8 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ :line_width, :line_style, :line_z, - :fillcolor, - :fillalpha, + :yfill_color, + :yfill_alpha, :fill_z, :marker_color, :marker_alpha, @@ -64,7 +64,7 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ :yerror, :zerror, :series_annotations, - :fillrange, + :yfill_range, ] @nospecialize @@ -82,11 +82,11 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ end # a tuple as fillrange has to be handled differently - if typeof(plotattributes[:fillrange]) <: Tuple - lower, upper = plotattributes[:fillrange] + if typeof(plotattributes[:yfill_range]) <: Tuple + lower, upper = plotattributes[:yfill_range] typeof(lower) <: AVec && (lower = _cycle(lower, indices)) typeof(upper) <: AVec && (upper = _cycle(upper, indices)) - plotattributes[:fillrange] = (lower, upper) + plotattributes[:yfill_range] = (lower, upper) end typeof(z) <: AVec && (z := z[indices]) @@ -218,7 +218,7 @@ make_steps(t::Tuple, st, even) = Tuple(make_steps(ti, st, even) for ti in t) seriestype := :path # handle fillrange - plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :pre, false) + plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :pre, false) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -243,7 +243,7 @@ end seriestype := :path # handle fillrange - plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, true) + plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :post, true) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -268,7 +268,7 @@ end seriestype := :path # handle fillrange - plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, false) + plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :post, false) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -430,7 +430,7 @@ end end # make fillto a vector... default fills to 0 - if (fillto = plotattributes[:fillrange]) === nothing + if (fillto = plotattributes[:yfill_range]) === nothing fillto = 0 end if yscale in _logScales && !all(_is_positive, fillto) @@ -510,7 +510,7 @@ end y_pts[inds] .= [ye[i], ye[i], ye[i + 1], ye[i + 1], ye[i]] fz[k] = z.surf[i, j] end - ensure_gradient!(plotattributes, :fillcolor, :fillalpha) + ensure_gradient!(plotattributes, :yfill_color, :yfill_alpha) fill_z := fz line_z := fz x := x_pts @@ -1340,7 +1340,7 @@ end yflip --> true colorbar --> false aspect_ratio --> :equal - z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) + z, plotattributes[:yfill_color] = replace_image_with_heatmap(mat) SliceIt, m, n, Surface(z) end end @@ -1405,7 +1405,7 @@ end seriestype := :heatmap yflip --> true colorbar --> false - z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) + z, plotattributes[:yfill_color] = replace_image_with_heatmap(mat) SliceIt, x, y, Surface(z) end end diff --git a/src/unitful.jl b/src/unitful.jl index e5552b5d5..1ac542952 100644 --- a/src/unitful.jl +++ b/src/unitful.jl @@ -50,7 +50,7 @@ function fixaxis!(attr, x, axisletter) ustripattribute!(attr, err, u) if axisletter === :y ustripattribute!(attr, :ribbon, u) - ustripattribute!(attr, :fillrange, u) + ustripattribute!(attr, :yfill_range, u) end fixaspectratio!(attr, u, axisletter) fixmarkercolor!(attr) diff --git a/src/utils.jl b/src/utils.jl index 29467dccb..31b0d4d35 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -384,8 +384,8 @@ function make_fillrange_from_ribbon(kw::AKW) rib = wraptuple(rib) rib1, rib2 = -first(rib), last(rib) # kw[:ribbon] = nothing - kw[:fillrange] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) - (get(kw, :fillalpha, nothing) === nothing) && (kw[:fillalpha] = 0.5) + kw[:yfill_range] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) + (get(kw, :yfill_alpha, nothing) === nothing) && (kw[:yfill_alpha] = 0.5) end #turn tuple of fillranges to one path @@ -425,7 +425,7 @@ ylims(sp_idx::Int = 1) = ylims(current(), sp_idx) zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) iscontour(series::Series) = series[:seriestype] in (:contour, :contour3d) -isfilledcontour(series::Series) = iscontour(series) && series[:fillrange] !== nothing +isfilledcontour(series::Series) = iscontour(series) && series[:yfill_range] !== nothing function contour_levels(series::Series, clims) iscontour(series) || error("Not a contour series") @@ -438,7 +438,7 @@ function contour_levels(series::Series, clims) levels end -for comp in (:line_, :fill, :marker_) +for comp in (:line_, :yfill_, :marker_) compcolor = string(comp, :color) get_compcolor = Symbol(:get_, compcolor) comp_z = string(comp, :z) @@ -448,7 +448,7 @@ for comp in (:line_, :fill, :marker_) @eval begin function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1) - c = series[$Symbol($compcolor)] # series[:line_color], series[:fillcolor], series[:marker_color] + c = series[$Symbol($compcolor)] # series[:line_color], series[:yfill_color], series[:marker_color] z = series[$Symbol($comp_z)] # series[:line_z], series[:fill_z], series[:marker_z] if z === nothing isa(c, ColorGradient) ? c : plot_color(_cycle(c, i)) @@ -475,7 +475,7 @@ end function get_colorgradient(series::Series) st = series[:seriestype] if st in (:surface, :heatmap) || isfilledcontour(series) - series[:fillcolor] + series[:yfill_color] elseif st in (:contour, :wireframe) series[:line_color] elseif series[:marker_z] !== nothing @@ -483,7 +483,7 @@ function get_colorgradient(series::Series) elseif series[:line_z] !== nothing series[:line_color] elseif series[:fill_z] !== nothing - series[:fillcolor] + series[:yfill_color] end end @@ -496,7 +496,7 @@ get_gradient(cp::ColorPalette) = cgrad(cp, categorical = true) get_linewidth(series, i::Int = 1) = _cycle(series[:line_width], i) get_linestyle(series, i::Int = 1) = _cycle(series[:line_style], i) -get_fillstyle(series, i::Int = 1) = _cycle(series[:fillstyle], i) +get_fillstyle(series, i::Int = 1) = _cycle(series[:yfill_style], i) function get_markerstrokecolor(series, i::Int = 1) msc = series[:marker_stroke_color] @@ -513,9 +513,9 @@ const _segmenting_vector_attributes = ( :line_alpha, :line_width, :line_style, - :fillcolor, - :fillalpha, - :fillstyle, + :yfill_color, + :yfill_alpha, + :yfill_style, :marker_color, :marker_alpha, :marker_size, diff --git a/test/test_defaults.jl b/test/test_defaults.jl index d96f82152..3f2a9869c 100644 --- a/test/test_defaults.jl +++ b/test/test_defaults.jl @@ -12,9 +12,9 @@ Plots._plots_theme_defaults() @testset "default" begin default(fillrange = 0) - @test Plots._series_defaults[:fillrange] == 0 + @test Plots._series_defaults[:yfill_range] == 0 pl = plot(1:5) - @test pl[1][1][:fillrange] == 0 + @test pl[1][1][:yfill_range] == 0 @test_nowarn default(legendfont = font(5)) pl = plot(1:5) @test pl[1][:legend_font_pointsize] == 5 diff --git a/test/test_misc.jl b/test/test_misc.jl index 11c26a20b..dd194bc34 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -158,7 +158,7 @@ end end @testset "Slicing" begin - @test plot(1:5, fillrange = 0)[1][1][:fillrange] == 0 + @test plot(1:5, fillrange = 0)[1][1][:yfill_range] == 0 data4 = rand(4, 4) mat = reshape(1:8, 2, 4) sp = plot(data4, ribbon = (mat, mat))[1] @@ -287,7 +287,7 @@ with(:gr) do y, z; connections = [ - [1, 2, 4, 3], # Quadrangle + [1, 2, 4, 3], # Quadrangle [1, 2, 5], # Triangle [2, 4, 5], # Triangle [4, 3, 5], # Triangle From aadc7a4f6a7c1b2d6c72b72f86e80cc15f33c64d Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Nov 2022 17:17:33 +0100 Subject: [PATCH 05/27] add alias_dict to add_attributes --- src/args.jl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/args.jl b/src/args.jl index 04156bbf4..5d48d5195 100644 --- a/src/args.jl +++ b/src/args.jl @@ -2154,15 +2154,28 @@ _series_index(plotattributes, sp) = #-------------------------------------------------- ## inspired by Base.@kwdef """ - add_attributes(level, expr[, match_table]) + add_attributes(level, expr, args...) Takes a `struct` definition and recurses into its fields to create keywords by chaining the field names with the structs' name with underscore. Also creates pluralized and non-underscore aliases for these keywords. - `level` indicates which group of `plot`, `subplot`, `series`, etc. the keywords belong to. - `expr` is the struct definition with default values like `Base.@kwdef` -- `match_table` is an expression of the form `:match = (symbols)`, with symbols whose default value should be `:match` +- `args` can be any of the following + - `match_table`: an expression of the form `:match = (symbols)`, with symbols whose default value should be `:match` + - `alias_dict`: an expression of the form `:aliases = Dict(symbol1 => symbol2)`, which will create aliases such that `symbol1` is an alias for `symbol2` """ -macro add_attributes(level, expr, match_table = :(:match = ())) +macro add_attributes(level, expr, args...) + match_table = :(:match = ()) + alias_dict = :(:aliases = Dict{Symbol, Symbol}()) + for arg in args + if arg.head == :(=) && arg.args[1] == QuoteNode(:match) + match_table = arg + elseif arg.head == :(=) && arg.args[1] == QuoteNode(:aliases) + alias_dict = arg + else + @warn "Unsupported extra argument $arg will be ignored" + end + end expr = macroexpand(__module__, expr) # to expand @static expr isa Expr && expr.head === :struct || error("Invalid usage of @add_attributes") if (T = expr.args[2]) isa Expr && T.head === :<: From 07aa4358f436581b59a6d247b1a7b78b0a943d00 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 2 Nov 2022 17:32:02 +0100 Subject: [PATCH 06/27] add some tests --- test/test_args.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_args.jl b/test/test_args.jl index a8f0d1c6d..89f2264d2 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -50,8 +50,15 @@ end :legend_font_color, :legend_title_font_family, :legend_title_font_color, + ) :aliases = Dict( + (:legend, :leg, :key) => :legend_position, + (:bg_legend, :bg_color_legend, :background_legend, :background_colour_legend, :bg_colour_legend, :background_color_legend) => :legend_background_color ) - @test true + @test Plots._subplot_defaults[:legend_font_family] == :match + @test Plots._subplot_defaults[:legend_column] == 1 + @test Plots._keyAliases[:legend] == :legend_position + @test Plots._keyAliases[:legends] == :legend_position + @test Plots._keyAliases[:bgcolour_legend] == :legend_background_color end @testset "aspect_ratio" begin From 79259686fb3d2addb09904bef89aa8e03365e0dc Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 3 Nov 2022 15:26:45 +0100 Subject: [PATCH 07/27] make aliases work --- src/args.jl | 40 +++++++++++++++++++++------------------- test/test_args.jl | 5 +++-- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/args.jl b/src/args.jl index 5d48d5195..99f405e69 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1,5 +1,9 @@ makeplural(s::Symbol) = last(string(s)) == 's' ? s : Symbol(string(s, "s")) -make_non_underscore(s::Symbol) = Symbol(replace(string(s), "_" => "")) +function make_non_underscore(s::Symbol) + str = string(s) + n = count("_", str) + Tuple(Symbol(replace(str, "_" => "", count = c)) for c in 1:n) +end const _keyAliases = Dict{Symbol,Symbol}() @@ -22,7 +26,9 @@ end function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}) for (k, v) in aliases if '_' in string(k) - aliases[make_non_underscore(k)] = v + for nu in make_non_underscore(k) + aliases[nu] = v + end end end end @@ -552,19 +558,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) = # ----------------------------------------------------------------------------- # legend -add_aliases(:legend_position, :legend, :leg, :key, :legends) -add_aliases( - :legend_background_color, - :bg_legend, - :bglegend, - :bgcolor_legend, - :bg_color_legend, - :background_legend, - :background_colour_legend, - :bgcolour_legend, - :bg_colour_legend, - :background_color_legend, -) add_aliases( :legend_foreground_color, :fg_legend, @@ -2166,12 +2159,12 @@ Also creates pluralized and non-underscore aliases for these keywords. """ macro add_attributes(level, expr, args...) match_table = :(:match = ()) - alias_dict = :(:aliases = Dict{Symbol, Symbol}()) + alias_dict = KW() for arg in args if arg.head == :(=) && arg.args[1] == QuoteNode(:match) match_table = arg elseif arg.head == :(=) && arg.args[1] == QuoteNode(:aliases) - alias_dict = arg + alias_dict = eval(arg.args[2]) else @warn "Unsupported extra argument $arg will be ignored" end @@ -2195,6 +2188,7 @@ macro add_attributes(level, expr, args...) value = QuoteNode(:match) end field = QuoteNode(Symbol("_", level, "_defaults")) + aliases = get(alias_dict, exp_key, nothing) push!( insert_block.args, Expr( @@ -2205,13 +2199,21 @@ macro add_attributes(level, expr, args...) :(Plots.add_aliases($(QuoteNode(exp_key)), $(QuoteNode(pl_key)))), :(Plots.add_aliases( $(QuoteNode(exp_key)), - $(QuoteNode(Plots.make_non_underscore(exp_key))), + $(QuoteNode(Plots.make_non_underscore(exp_key)))..., )), :(Plots.add_aliases( $(QuoteNode(exp_key)), - $(QuoteNode(Plots.make_non_underscore(pl_key))), + $(QuoteNode(Plots.make_non_underscore(pl_key)))..., )), ) + if aliases !== nothing + pl_aliases = Plots.makeplural.(aliases) + push!( + insert_block.args, + :(Plots.add_aliases($(QuoteNode(exp_key)), $(aliases)..., $(pl_aliases)..., $(Iterators.flatten(Plots.make_non_underscore.(aliases)))..., $(Iterators.flatten(Plots.make_non_underscore.(pl_aliases)))..., + )) + ) + end end quote Base.@kwdef $original diff --git a/test/test_args.jl b/test/test_args.jl index 89f2264d2..e2b80e619 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -51,13 +51,14 @@ end :legend_title_font_family, :legend_title_font_color, ) :aliases = Dict( - (:legend, :leg, :key) => :legend_position, - (:bg_legend, :bg_color_legend, :background_legend, :background_colour_legend, :bg_colour_legend, :background_color_legend) => :legend_background_color + :legend_position => (:legend, :leg, :key), + :legend_background_color => (:bg_legend, :bg_color_legend, :background_legend, :background_colour_legend, :bg_colour_legend, :background_color_legend) ) @test Plots._subplot_defaults[:legend_font_family] == :match @test Plots._subplot_defaults[:legend_column] == 1 @test Plots._keyAliases[:legend] == :legend_position @test Plots._keyAliases[:legends] == :legend_position + @test Plots._keyAliases[:bgcolourlegend] == :legend_background_color @test Plots._keyAliases[:bgcolour_legend] == :legend_background_color end From f931f7a7d72263ae72e709657cd5a87765c2074e Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 3 Nov 2022 16:18:20 +0100 Subject: [PATCH 08/27] complete legend aliases --- src/args.jl | 30 +++++++----------------------- src/components.jl | 4 ++++ test/test_args.jl | 4 +++- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/args.jl b/src/args.jl index 99f405e69..f7a4d7359 100644 --- a/src/args.jl +++ b/src/args.jl @@ -6,9 +6,16 @@ function make_non_underscore(s::Symbol) end const _keyAliases = Dict{Symbol,Symbol}() +const _generalAliases = ("background" => "bg", "foreground" => "fg", "pointsize" => "size", "yfill" => "fill") function add_aliases(sym::Symbol, aliases::Symbol...) for alias in aliases + str = string(alias) + for ga in _generalAliases + contains(str, ga.first) || continue + str2 = replace(str, ga) + _keyAliases[Symbol(str2)] = sym + end (haskey(_keyAliases, alias) || alias === sym) && return _keyAliases[alias] = sym end @@ -557,29 +564,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) = filter((x) -> x.second == val, aliasMap) |> keys |> collect |> sort # ----------------------------------------------------------------------------- -# legend -add_aliases( - :legend_foreground_color, - :fg_legend, - :fglegend, - :fgcolor_legend, - :fg_color_legend, - :foreground_legend, - :foreground_colour_legend, - :fgcolour_legend, - :fg_colour_legend, - :foreground_color_legend, -) -add_aliases(:legend_font_pointsize, :legendfontsize) -add_aliases( - :legend_title, - :key_title, - :keytitle, - :label_title, - :labeltitle, - :leg_title, - :legtitle, -) add_aliases(:legend_title_font_pointsize, :legendtitlefontsize) # margin add_aliases(:left_margin, :leftmargin) diff --git a/src/components.jl b/src/components.jl index 600acd5a4..815112d4f 100644 --- a/src/components.jl +++ b/src/components.jl @@ -832,6 +832,10 @@ end :match = ( :legend_font_color, :legend_title_font_family, :legend_title_font_color, +) :aliases = Dict( + :legend_position => (:legend, :leg, :key), + :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), + :legend_foreground_color => (:foreground_legend, :foreground_colour_legend, :foreground_colour_legend) ) ### Line diff --git a/test/test_args.jl b/test/test_args.jl index e2b80e619..58e754b05 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -52,7 +52,8 @@ end :legend_title_font_color, ) :aliases = Dict( :legend_position => (:legend, :leg, :key), - :legend_background_color => (:bg_legend, :bg_color_legend, :background_legend, :background_colour_legend, :bg_colour_legend, :background_color_legend) + :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), + :legend_title = (:key_title, :label_title, :leg_title), ) @test Plots._subplot_defaults[:legend_font_family] == :match @test Plots._subplot_defaults[:legend_column] == 1 @@ -60,6 +61,7 @@ end @test Plots._keyAliases[:legends] == :legend_position @test Plots._keyAliases[:bgcolourlegend] == :legend_background_color @test Plots._keyAliases[:bgcolour_legend] == :legend_background_color + @test Plots._keyAliases[:legendfontsize] == :legend_font_pointsize end @testset "aspect_ratio" begin From dd1f611db95369170beeabc6d1cd9cc7cb73c57c Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 3 Nov 2022 16:35:11 +0100 Subject: [PATCH 09/27] add aliases to plotattr --- src/plotattr.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plotattr.jl b/src/plotattr.jl index d1396cbf5..31334d80a 100644 --- a/src/plotattr.jl +++ b/src/plotattr.jl @@ -55,6 +55,7 @@ function plotattr() - $attrtype attribute - Default: $(d isa Symbol ? string(':', d) : d) - $(get(Plots._arg_desc, attr, "")) + - Aliases: $('`' * join(letter .* string.(aliases(attr)), "`, `") * '`') """) end # COV_EXCL_STOP From 65fc04cf556253f7163eea33633441451e770974 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 3 Nov 2022 17:17:40 +0100 Subject: [PATCH 10/27] move aliases --- src/args.jl | 17 +---------------- src/components.jl | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/args.jl b/src/args.jl index f7a4d7359..6b4be8feb 100644 --- a/src/args.jl +++ b/src/args.jl @@ -6,7 +6,7 @@ function make_non_underscore(s::Symbol) end const _keyAliases = Dict{Symbol,Symbol}() -const _generalAliases = ("background" => "bg", "foreground" => "fg", "pointsize" => "size", "yfill" => "fill") +const _generalAliases = ("background" => "bg", "foreground" => "fg", "pointsize" => "size", "yfill" => "fill", "alpha" => "a", "alpha" => "opacity", "alpha" => "α") function add_aliases(sym::Symbol, aliases::Symbol...) for alias in aliases @@ -564,7 +564,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) = filter((x) -> x.second == val, aliasMap) |> keys |> collect |> sort # ----------------------------------------------------------------------------- -add_aliases(:legend_title_font_pointsize, :legendtitlefontsize) # margin add_aliases(:left_margin, :leftmargin) @@ -574,11 +573,6 @@ add_aliases(:right_margin, :rightmargin) # colors add_aliases(:seriescolor, :c, :color, :colour) -add_aliases(:line_color, :lc, :lcolor, :lcolour, :linecolour) -add_aliases(:marker_color, :mc, :mcolor, :mcolour, :markercolour) -add_aliases(:marker_stroke_color, :msc, :mscolor, :mscolour, :markerstrokecolour) -add_aliases(:marker_stroke_width, :msw, :mswidth) -add_aliases(:yfill_color, :fc, :fcolor, :fcolour, :fillcolour) add_aliases( :background_color, @@ -793,10 +787,6 @@ add_aliases( # alphas add_aliases(:seriesalpha, :alpha, :α, :opacity) -add_aliases(:line_alpha, :la, :lalpha, :lα, :lineopacity, :lopacity) -add_aliases(:marker_alpha, :ma, :malpha, :mα, :markeropacity, :mopacity) -add_aliases(:marker_stroke_alpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) -add_aliases(:yfill_alpha, :fa, :falpha, :fα, :fillopacity, :fopacity) # axes attributes add_axes_aliases(:guide, :label, :lab, :l; generic = false) @@ -876,15 +866,10 @@ add_axes_aliases( add_aliases(:seriestype, :st, :t, :typ, :linetype, :lt) add_aliases(:label, :lab) add_aliases(:line, :l) -add_aliases(:line_width, :w, :width, :lw) -add_aliases(:line_style, :style, :s, :ls) add_aliases(:marker, :m, :mark) -add_aliases(:marker_shape, :shape) -add_aliases(:marker_size, :ms, :msize) add_aliases(:marker_z, :markerz, :zcolor, :mz) add_aliases(:line_z, :linez, :zline, :lz) add_aliases(:fill, :f, :area) -add_aliases(:yfill_range, :fillrng, :frange, :fillto, :fill_between) add_aliases(:group, :g, :grouping) add_aliases(:bins, :bin, :nbin, :nbins, :nb) add_aliases(:ribbon, :rib) diff --git a/src/components.jl b/src/components.jl index 815112d4f..f695f6d10 100644 --- a/src/components.jl +++ b/src/components.jl @@ -845,7 +845,13 @@ end :match = ( width = :auto color = :auto alpha = nothing -end +end :aliases = Dict( + :line_color => (:lc, :lcolor, :lcolour, :line_colour), + :line_alpha => (:lalpha,), + :line_width => (:w, :width, :lw), + :line_style => (:s, :style, :ls), + +) ### Marker @@ -855,7 +861,15 @@ end alpha = nothing stroke::Line = Line(:solid, 1, :match, nothing) size = 4 -end +end :aliases = Dict( + :marker_color => (:mc, :mcolor, :mcolour, :marker_colour), + :marker_alpha => (:malpha,), + :marker_shape => (:shape,), + :marker_size => (:ms, :msize), + :marker_stroke_color => (:msc, :mscolor, :mscolour), + :marker_stroke_alpha => (:msalpha,), + :marker_stroke_width => (:msw, :mswidth), +) ### Errorbars @@ -872,4 +886,8 @@ end color = :match alpha = nothing style = nothing -end +end aliases = Dict( + :yfill_color => (:fc, :fcolor, :fcolour,), + :yfill_alpha => (:falpha,), + :yfill_range => (:yfill_rng, :frange, :yfill_to, :yfill_between) +) From 2ddf825e702e775424131b0444811e0a17d1ff79 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 10 Nov 2022 22:01:33 +0100 Subject: [PATCH 11/27] remove fill and errorbar --- src/components.jl | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/components.jl b/src/components.jl index f695f6d10..b8895af27 100644 --- a/src/components.jl +++ b/src/components.jl @@ -871,23 +871,3 @@ end :aliases = Dict( :marker_stroke_width => (:msw, :mswidth), ) -### Errorbars - -@add_attributes series struct XErrorBar - color = :match - shape = :hline - -end - -### Fills - -@add_attributes series struct YFill - range = nothing - color = :match - alpha = nothing - style = nothing -end aliases = Dict( - :yfill_color => (:fc, :fcolor, :fcolour,), - :yfill_alpha => (:falpha,), - :yfill_range => (:yfill_rng, :frange, :yfill_to, :yfill_between) -) From 0efda094883c6df3750ea43ed75a2f0aa1d0d284 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 10 Nov 2022 22:04:58 +0100 Subject: [PATCH 12/27] Revert "rename yfill -> fill" This reverts commit da25f973fbab216498cdb0c96268e43b9778b76d. --- NEWS.md | 4 +- RecipesPipeline/src/series_recipe.jl | 2 +- src/arg_desc.jl | 8 ++-- src/args.jl | 45 ++++++++++++---------- src/axes.jl | 4 +- src/backends.jl | 46 +++++++++++------------ src/backends/deprecated/pgfplots.jl | 10 ++--- src/backends/gaston.jl | 4 +- src/backends/gr.jl | 20 +++++----- src/backends/inspectdr.jl | 2 +- src/backends/pgfplotsx.jl | 4 +- src/backends/plotly.jl | 56 ++++++++++++++-------------- src/backends/pyplot.jl | 20 +++++----- src/pipeline.jl | 6 +-- src/recipes.jl | 26 ++++++------- src/unitful.jl | 2 +- src/utils.jl | 22 +++++------ test/test_defaults.jl | 4 +- test/test_misc.jl | 4 +- 19 files changed, 148 insertions(+), 141 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8eb76b21e..8e8d79d40 100644 --- a/NEWS.md +++ b/NEWS.md @@ -590,7 +590,7 @@ Many updates, min julia 1.0 - allow calling `plot!(sp, ...)` to update a target Subplot - PyPlot: zorder fix - new DataFrames logic/recipe: more flexible/robust and allow Symbols for: - - `(:yfill_range, :line_z, :marker_z, :marker_size, :ribbon, :weights, :xerror, :yerror)` + - `(:fillrange, :line_z, :marker_z, :marker_size, :ribbon, :weights, :xerror, :yerror)` - new `display_type` and `extra_kwargs` plot attributes - surface fix @@ -808,7 +808,7 @@ Many updates, min julia 1.0 - New dependency on Requires, allows auto-loading of DataFrames support - Support for plotting lists of Tuples and FixedSizeArrays - new `@animate` macro for super simple animations (see https://github.com/tbreloff/Plots.jl/issues/111#issuecomment-181515616) -- allow Function for `:yfill_range` and `zcolor` arguments (for example: `scatter(sin, 0:10, marker=15, fill=(cos,0.4), zcolor=sin)`) +- allow Function for `:fillrange` and `zcolor` arguments (for example: `scatter(sin, 0:10, marker=15, fill=(cos,0.4), zcolor=sin)`) - allow vectors of PlotText without x/y coords (for example: `scatter(rand(10), m=20, ann=map(text, 1:10))`) - Lots and lots of fixes diff --git a/RecipesPipeline/src/series_recipe.jl b/RecipesPipeline/src/series_recipe.jl index 8f8cdc9bc..bb4275803 100644 --- a/RecipesPipeline/src/series_recipe.jl +++ b/RecipesPipeline/src/series_recipe.jl @@ -37,7 +37,7 @@ function _process_seriesrecipe(plt, plotattributes) # shapes shouldn't have fillrange set if plotattributes[:seriestype] == :shape - plotattributes[:yfill_range] = nothing + plotattributes[:fillrange] = nothing end # if it's natively supported, finalize processing and pass along to the backend, diff --git a/src/arg_desc.jl b/src/arg_desc.jl index a62cba8f6..f85d02d2d 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -10,11 +10,11 @@ const _arg_desc = KW( :line_width => "Number. Width of the line (in pixels)", :line_color => "Color Type. Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default).", :line_alpha => "Number in [0,1]. The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor.", - :yfill_range => "Number or AbstractVector. Fills area between fillrange and y for line-types, sets the base for bar/stick types, and similar for other types.", - :yfill_color => "Color Type. Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`.", - :yfill_alpha => "Number in [0,1]. The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor.", + :fillrange => "Number or AbstractVector. Fills area between fillrange and y for line-types, sets the base for bar/stick types, and similar for other types.", + :fillcolor => "Color Type. Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`.", + :fillalpha => "Number in [0,1]. The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor.", :marker_shape => "Symbol, Shape, or AbstractVector. Choose from $(_allMarkers).", - :yfill_style => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", + :fillstyle => "Symbol. Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x", :marker_color => "Color Type. Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`.", :marker_alpha => "Number in [0,1]. The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor.", :marker_size => "Number or AbstractVector. Size (radius pixels) of the markers", diff --git a/src/args.jl b/src/args.jl index 6b4be8feb..5705891b3 100644 --- a/src/args.jl +++ b/src/args.jl @@ -338,6 +338,10 @@ const _series_defaults = KW( :seriescolor => :auto, :seriesalpha => nothing, :seriestype => :path, + :fillrange => nothing, # ribbons, areas, etc + :fillcolor => :match, + :fillalpha => nothing, + :fillstyle => nothing, :bins => :auto, # number of bins for hists :smooth => false, # regression line? :group => nothing, # groupby vector @@ -573,6 +577,7 @@ add_aliases(:right_margin, :rightmargin) # colors add_aliases(:seriescolor, :c, :color, :colour) +add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) add_aliases( :background_color, @@ -787,6 +792,7 @@ add_aliases( # alphas add_aliases(:seriesalpha, :alpha, :α, :opacity) +add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) # axes attributes add_axes_aliases(:guide, :label, :lab, :l; generic = false) @@ -870,6 +876,7 @@ add_aliases(:marker, :m, :mark) add_aliases(:marker_z, :markerz, :zcolor, :mz) add_aliases(:line_z, :linez, :zline, :lz) add_aliases(:fill, :f, :area) +add_aliases(:fillrange, :fillrng, :frange, :fillto, :fill_between) add_aliases(:group, :g, :grouping) add_aliases(:bins, :bin, :nbin, :nbins, :nb) add_aliases(:ribbon, :rib) @@ -1084,13 +1091,13 @@ function processLineArg(plotattributes::AKW, arg) arg.style === nothing || (plotattributes[:line_style] = arg.style) elseif typeof(arg) <: Brush - arg.size === nothing || (plotattributes[:yfill_range] = arg.size) + arg.size === nothing || (plotattributes[:fillrange] = arg.size) arg.color === nothing || ( - plotattributes[:yfill_color] = + plotattributes[:fillcolor] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:yfill_alpha] = arg.alpha) - arg.style === nothing || (plotattributes[:yfill_style] = arg.style) + arg.alpha === nothing || (plotattributes[:fillalpha] = arg.alpha) + arg.style === nothing || (plotattributes[:fillstyle] = arg.style) elseif typeof(arg) <: Arrow || arg in (:arrow, :arrows) plotattributes[:arrow] = arg @@ -1154,35 +1161,35 @@ function processMarkerArg(plotattributes::AKW, arg) end function processFillArg(plotattributes::AKW, arg) - # fr = get(plotattributes, :yfill_range, 0) + # fr = get(plotattributes, :fillrange, 0) if typeof(arg) <: Brush - arg.size === nothing || (plotattributes[:yfill_range] = arg.size) + arg.size === nothing || (plotattributes[:fillrange] = arg.size) arg.color === nothing || ( - plotattributes[:yfill_color] = + plotattributes[:fillcolor] = arg.color === :auto ? :auto : plot_color(arg.color) ) - arg.alpha === nothing || (plotattributes[:yfill_alpha] = arg.alpha) - arg.style === nothing || (plotattributes[:yfill_style] = arg.style) + arg.alpha === nothing || (plotattributes[:fillalpha] = arg.alpha) + arg.style === nothing || (plotattributes[:fillstyle] = arg.style) elseif typeof(arg) <: Bool - plotattributes[:yfill_range] = arg ? 0 : nothing + plotattributes[:fillrange] = arg ? 0 : nothing # fillrange function elseif allFunctions(arg) - plotattributes[:yfill_range] = arg + plotattributes[:fillrange] = arg # fillalpha elseif allAlphas(arg) - plotattributes[:yfill_alpha] = arg + plotattributes[:fillalpha] = arg # fillrange provided as vector or number elseif typeof(arg) <: Union{AbstractArray{<:Real},Real} - plotattributes[:yfill_range] = arg + plotattributes[:fillrange] = arg - elseif !handleColors!(plotattributes, arg, :yfill_color) - plotattributes[:yfill_range] = arg + elseif !handleColors!(plotattributes, arg, :fillcolor) + plotattributes[:fillrange] = arg end - # plotattributes[:yfill_range] = fr + # plotattributes[:fillrange] = fr nothing end @@ -2039,7 +2046,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) ) # update alphas - for asym in (:line_alpha, :marker_alpha, :yfill_alpha) + for asym in (:line_alpha, :marker_alpha, :fillalpha) if plotattributes[asym] === nothing plotattributes[asym] = plotattributes[:seriesalpha] end @@ -2054,7 +2061,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) plotattributes[:seriescolor] = scolor = get_series_color(scolor, sp, plotIndex, stype) # update other colors - for s in (:line_, :marker_, :yfill_) + for s in (:line_, :marker_, :fill) csym, asym = Symbol(s, :color), Symbol(s, :alpha) plotattributes[csym] = if plotattributes[csym] === :auto plot_color(if has_black_border_for_default(stype) && s === :line @@ -2086,7 +2093,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) ensure_gradient!(plotattributes, :line_color, :line_alpha) end if plotattributes[:fill_z] !== nothing - ensure_gradient!(plotattributes, :yfill_color, :yfill_alpha) + ensure_gradient!(plotattributes, :fillcolor, :fillalpha) end # scatter plots don't have a line, but must have a shape diff --git a/src/axes.jl b/src/axes.jl index c04fb30d5..3f6470aa7 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -453,7 +453,7 @@ function expand_extrema!(sp::Subplot, plotattributes::AKW) # end # expand for fillrange - fr = plotattributes[:yfill_range] + fr = plotattributes[:fillrange] if fr === nothing && plotattributes[:seriestype] === :bar fr = 0.0 end @@ -512,7 +512,7 @@ end scale_lims!([plt], [letter], factor) Scale the limits of the axis specified by `letter` (one of `:x`, `:y`, `:z`) by the -given `factor` around the limits' middle point. +given `factor` around the limits' middle point. If `letter` is omitted, all axes are affected. """ function scale_lims!(sp::Subplot, letter, factor) diff --git a/src/backends.jl b/src/backends.jl index 4bccaf0ba..71cd5b129 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -315,10 +315,10 @@ const _gr_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :yfill_range, - :yfill_color, - :yfill_alpha, - :yfill_style, + :fillrange, + :fillcolor, + :fillalpha, + :fillstyle, :bins, :layout, :title, @@ -448,9 +448,9 @@ const _plotly_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - :yfill_range, - :yfill_color, - :yfill_alpha, + :fillrange, + :fillcolor, + :fillalpha, :bins, :title, :titlelocation, @@ -573,9 +573,9 @@ const _pgfplots_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - :yfill_range, - :yfill_color, - :yfill_alpha, + :fillrange, + :fillcolor, + :fillalpha, :bins, # :bar_width, :bar_edges, :title, @@ -687,10 +687,10 @@ const _pyplot_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :yfill_range, - :yfill_color, - :yfill_alpha, - :yfill_style, + :fillrange, + :fillcolor, + :fillalpha, + :fillstyle, :bins, :bar_width, :bar_edges, @@ -806,7 +806,7 @@ const _gaston_attr = merge_with_base_supported([ :marker_size, :marker_alpha, # :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, - # :yfill_range, :yfill_color, :yfill_alpha, + # :fillrange, :fillcolor, :fillalpha, # :bins, # :bar_width, :bar_edges, :title, @@ -988,9 +988,9 @@ const _hdf5_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :yfill_range, - :yfill_color, - :yfill_alpha, + :fillrange, + :fillcolor, + :fillalpha, :bins, :bar_width, :bar_edges, @@ -1094,8 +1094,8 @@ const _inspectdr_attr = merge_with_base_supported([ :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, #Causes warning not to have it... what is this? - :yfill_color, - :yfill_alpha, #:yfill_range, + :fillcolor, + :fillalpha, #:fillrange, # :bins, :bar_width, :bar_edges, :bar_position, :title, :titlelocation, @@ -1195,9 +1195,9 @@ const _pgfplotsx_attr = merge_with_base_supported([ :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, - :yfill_range, - :yfill_color, - :yfill_alpha, + :fillrange, + :fillcolor, + :fillalpha, :bins, :layout, :title, diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 2c241a63a..780ecf748 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -225,12 +225,12 @@ function pgf_series(sp::Subplot, series::Series) # add to legend? if i == 1 && sp[:legend_position] !== :none && should_add_to_legend(series) - if plotattributes[:yfill_range] !== nothing + if plotattributes[:fillrange] !== nothing push!(style, "forget plot") push!(series_collection, pgf_fill_legend_hack(plotattributes, args)) else kw[:legendentry] = plotattributes[:label] - if st === :shape # || plotattributes[:yfill_range] !== nothing + if st === :shape # || plotattributes[:fillrange] !== nothing push!(style, "area legend") end end @@ -247,13 +247,13 @@ function pgf_series(sp::Subplot, series::Series) kw[:style] = join(style, ',') # add fillrange - if series[:yfill_range] !== nothing && st !== :shape + if series[:fillrange] !== nothing && st !== :shape push!( series_collection, pgf_fillrange_series( series, i, - _cycle(series[:yfill_range], rng), + _cycle(series[:fillrange], rng), seg_args..., ), ) @@ -641,7 +641,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) # As it is likely that all series within the same axis use the same # colormap this should not cause any problem. for series in series_list(sp) - for col in (:marker_color, :yfill_color, :line_color) + for col in (:marker_color, :fillcolor, :line_color) if typeof(series.plotattributes[col]) == ColorGradient push!( style, diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index 955723721..b19ec5c84 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -219,7 +219,7 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series) if gsp.dims == 2 && z === nothing for (n, seg) in enumerate(series_segments(series, st; check = true)) i, rng = seg.attr_index, seg.range - fr = _cycle(series[:yfill_range], 1:length(x[rng])) + fr = _cycle(series[:fillrange], 1:length(x[rng])) for sc in gaston_seriesconf!(sp, series, i, n == 1) push!(curves, Gaston.Curve(x[rng], y[rng], nothing, fr, sc)) end @@ -293,7 +293,7 @@ function gaston_seriesconf!( pt, ps, mc = gaston_mk_ms_mc(series, clims, i) push!(curveconf, "w points pt $pt ps $ps lc $mc") elseif st ∈ (:path, :straightline, :path3d) - fr = series[:yfill_range] + fr = series[:fillrange] fc = gaston_color(get_fillcolor(series, i), get_fillalpha(series, i)) fs = get_fillstyle(series, i) # FIXME: add fillstyle support ? lc, dt, lw = gaston_lc_ls_lw(series, clims, i) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 89296cf26..065299b26 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1010,7 +1010,7 @@ function gr_add_legend(sp, leg, viewport_area) _debugMode[] && gr_legend_bbox(xpos, ypos, leg) if ( - (st === :shape || series[:yfill_range] !== nothing) && + (st === :shape || series[:fillrange] !== nothing) && series[:ribbon] === nothing ) (fc = get_fillcolor(series, clims)) |> gr_set_fill @@ -1649,7 +1649,7 @@ function gr_add_series(sp, series) x, y, z = map(letter -> handle_surface(series[letter]), (:x, :y, :z)) xscale, yscale = sp[:xaxis][:scale], sp[:yaxis][:scale] - frng = series[:yfill_range] + frng = series[:fillrange] # recompute data if ispolar(sp) && z === nothing @@ -1829,7 +1829,7 @@ function gr_draw_contour(series, x, y, z, clims) gr_set_line(get_linewidth(series), get_linestyle(series), get_line_color(series), series) gr_set_transparency(get_fillalpha(series)) h = gr_contour_levels(series, clims) - if series[:yfill_range] !== nothing + if series[:fillrange] !== nothing GR.contourf(x, y, h, z, series[:contour_labels] == true ? 1 : 0) else black = plot_color(:black) @@ -1885,10 +1885,10 @@ function gr_draw_surface(series, x, y, z, clims) ArgumentError |> throw end - facecolor = if series[:yfill_color] isa AbstractArray - series[:yfill_color] + facecolor = if series[:fillcolor] isa AbstractArray + series[:fillcolor] else - fill(series[:yfill_color], length(cns)) + fill(series[:fillcolor], length(cns)) end fillalpha = get_fillalpha(series) facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor) @@ -1902,7 +1902,7 @@ function gr_draw_surface(series, x, y, z, clims) end function gr_draw_heatmap(series, x, y, z, clims) - fillgrad = _as_gradient(series[:yfill_color]) + fillgrad = _as_gradient(series[:fillcolor]) GR.setprojectiontype(0) GR.setspace(clims..., 0, 90) w, h = length(x) - 1, length(y) - 1 @@ -1914,18 +1914,18 @@ function gr_draw_heatmap(series, x, y, z, clims) # Note that drawimage draws uniformly spaced data correctly # even on log scales, where it is visually non-uniform. colors, _z = if sp[:colorbar_scale] === :identity - plot_color.(get(fillgrad, z, clims), series[:yfill_alpha]), z + plot_color.(get(fillgrad, z, clims), series[:fillalpha]), z elseif sp[:colorbar_scale] === :log10 z_log = replace(x -> isinf(x) ? NaN : x, log10.(z)) z_normalized = get_z_normalized.(z_log, log10.(clims)...) - plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:yfill_alpha]), z_log + plot_color.(map(z -> get(fillgrad, z), z_normalized), series[:fillalpha]), z_log end for i in eachindex(colors) isnan(_z[i]) && (colors[i] = set_RGBA_alpha(0, colors[i])) end GR.drawimage(first(x), last(x), last(y), first(y), w, h, gr_color.(colors)) else - if something(series[:yfill_alpha], 1) < 1 + if something(series[:fillalpha], 1) < 1 @warn "GR: transparency not supported in non-uniform heatmaps. Alpha values ignored." end z_normalized, _z = if sp[:colorbar_scale] === :identity diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 21cf8bc3b..0411f3d38 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -240,7 +240,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) end #= TODO: Eventually support - series[:yfill_color] #I think this is fill under line + series[:fillcolor] #I think this is fill under line zorder = series[:series_plotindex] For st in :shape: diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index c04fd5f70..fcf95085f 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -283,7 +283,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) PGFPlotsX.Plot end if ( - series[:yfill_range] !== nothing && + series[:fillrange] !== nothing && series[:ribbon] === nothing && !isfilledcontour(series) ) @@ -359,7 +359,7 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o segment_opt = merge(segment_opt, pgfx_marker(opt, i)) end # add fillrange - if (sf = opt[:yfill_range]) !== nothing && !isfilledcontour(series) + if (sf = opt[:fillrange]) !== nothing && !isfilledcontour(series) if sf isa Number || sf isa AVec pgfx_fillrange_series!(axis, series, series_func, i, _cycle(sf, rng), rng) elseif sf isa Tuple && series[:ribbon] !== nothing diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index dd20dfc7c..eff913e5d 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -544,7 +544,7 @@ function plotly_series(plt::Plot, series::Series) hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && - (isa(series[:yfill_range], AbstractVector) || isa(series[:yfill_range], Tuple)) + (isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple)) plotattributes_out[:colorbar] = KW(:title => sp[:colorbar_title]) @@ -562,7 +562,7 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:type] = "heatmap" plotattributes_out[:x], plotattributes_out[:y], plotattributes_out[:z] = x, y, z plotattributes_out[:colorscale] = - plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) + plotly_colorscale(series[:fillcolor], series[:fillalpha]) plotattributes_out[:showscale] = hascolorbar(sp) elseif st === :contour @@ -617,8 +617,8 @@ function plotly_series(plt::Plot, series::Series) plotattributes_out[:showscale] = false else plotattributes_out[:colorscale] = - plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) - plotattributes_out[:opacity] = series[:yfill_alpha] + plotly_colorscale(series[:fillcolor], series[:fillalpha]) + plotattributes_out[:opacity] = series[:fillalpha] if series[:fill_z] !== nothing plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z]) end @@ -661,10 +661,10 @@ function plotly_series(plt::Plot, series::Series) end end plotattributes_out[:colorscale] = - plotly_colorscale(series[:yfill_color], series[:yfill_alpha]) + plotly_colorscale(series[:fillcolor], series[:fillalpha]) plotattributes_out[:color] = - rgba_string(plot_color(series[:yfill_color], series[:yfill_alpha])) - plotattributes_out[:opacity] = series[:yfill_alpha] + rgba_string(plot_color(series[:fillcolor], series[:fillalpha])) + plotattributes_out[:opacity] = series[:fillalpha] if series[:fill_z] !== nothing plotattributes_out[:surfacecolor] = handle_surface(series[:fill_z]) end @@ -742,7 +742,7 @@ function plotly_series_shapes(plt::Plot, series::Series, clims) :x => vcat(x[rng], x[rng[1]]), :y => vcat(y[rng], y[rng[1]]), :fill => "tozeroy", - :yfill_color => rgba_string( + :fillcolor => rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ), ), @@ -782,7 +782,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z hasline = st in (:path, :path3d, :straightline) hasfillrange = st in (:path, :scatter, :scattergl, :straightline) && - (isa(series[:yfill_range], AbstractVector) || isa(series[:yfill_range], Tuple)) + (isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple)) segments = collect(series_segments(series, st)) plotattributes_outs = fill(KW(), (hasfillrange ? 2 : 1) * length(segments)) @@ -804,20 +804,20 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z else hasline ? "lines" : "none" end - if series[:yfill_range] == true || - series[:yfill_range] == 0 || - isa(series[:yfill_range], Tuple) + if series[:fillrange] == true || + series[:fillrange] == 0 || + isa(series[:fillrange], Tuple) plotattributes_out[:fill] = "tozeroy" - plotattributes_out[:yfill_color] = rgba_string( + plotattributes_out[:fillcolor] = rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ) - elseif typeof(series[:yfill_range]) <: Union{AbstractVector{<:Real},Real} + elseif typeof(series[:fillrange]) <: Union{AbstractVector{<:Real},Real} plotattributes_out[:fill] = "tonexty" - plotattributes_out[:yfill_color] = rgba_string( + plotattributes_out[:fillcolor] = rgba_string( plot_color(get_fillcolor(series, clims, i), get_fillalpha(series, i)), ) - elseif !(series[:yfill_range] in (false, nothing)) - @warn "fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:yfill_range])" + elseif !(series[:fillrange] in (false, nothing)) + @warn "fillrange ignored... plotly only supports filling to zero and to a vector of values. fillrange: $(series[:fillrange])" end plotattributes_out[:x], plotattributes_out[:y] = x[rng], y[rng] @@ -901,29 +901,29 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z plotattributes_out_fillrange = deepcopy(plotattributes_out) plotattributes_out_fillrange[:showlegend] = false # if fillrange is provided as real or tuple of real, expand to array - if typeof(series[:yfill_range]) <: Real - plotattributes_out[:yfill_range] = fill(series[:yfill_range], length(rng)) - elseif typeof(series[:yfill_range]) <: Tuple + if typeof(series[:fillrange]) <: Real + plotattributes_out[:fillrange] = fill(series[:fillrange], length(rng)) + elseif typeof(series[:fillrange]) <: Tuple f1 = - (fr1 = series[:yfill_range][1]) |> typeof <: Real ? + (fr1 = series[:fillrange][1]) |> typeof <: Real ? fill(fr1, length(rng)) : fr1[rng] f2 = - (fr2 = series[:yfill_range][2]) |> typeof <: Real ? + (fr2 = series[:fillrange][2]) |> typeof <: Real ? fill(fr2, length(rng)) : fr2[rng] - plotattributes_out[:yfill_range] = (f1, f2) + plotattributes_out[:fillrange] = (f1, f2) end - if isa(series[:yfill_range], AbstractVector) - plotattributes_out_fillrange[:y] = series[:yfill_range][rng] + if isa(series[:fillrange], AbstractVector) + plotattributes_out_fillrange[:y] = series[:fillrange][rng] delete!(plotattributes_out_fillrange, :fill) - delete!(plotattributes_out_fillrange, :yfill_color) + delete!(plotattributes_out_fillrange, :fillcolor) else # if fillrange is a tuple with upper and lower limit, plotattributes_out_fillrange # is the series that will do the filling plotattributes_out_fillrange[:x], plotattributes_out_fillrange[:y] = - concatenate_fillrange(x[rng], series[:yfill_range]) + concatenate_fillrange(x[rng], series[:fillrange]) plotattributes_out_fillrange[:line][:width] = 0 delete!(plotattributes_out, :fill) - delete!(plotattributes_out, :yfill_color) + delete!(plotattributes_out, :fillcolor) end plotattributes_outs[(2k - 1):(2k)] = diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 8bbcc1f7a..b06445550 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -246,7 +246,7 @@ py_linecolormap(series::Series) = py_markercolormap(series::Series) = py_colormap(cgrad(series[:marker_color], alpha = get_marker_alpha(series))) py_fillcolormap(series::Series) = - py_colormap(cgrad(series[:yfill_color], alpha = get_fillalpha(series))) + py_colormap(cgrad(series[:fillcolor], alpha = get_fillalpha(series))) # --------------------------------------------------------------------------- @@ -537,7 +537,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) C = series[:weights], gridsize = series[:bins] === :auto ? 100 : series[:bins], # 100 is the default value linewidths = py_thickness_scale(plt, series[:line_width]), - alpha = series[:yfill_alpha], + alpha = series[:fillalpha], cmap = py_fillcolormap(series), # applies to the pcolorfast object zorder = series[:series_plotindex], extrakw..., @@ -577,7 +577,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) push!(handles, handle) # contour fills - if series[:yfill_range] !== nothing + if series[:fillrange] !== nothing handle = ax."contourf"( x, y, @@ -585,7 +585,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) levelargs...; label = series[:label], zorder = series[:series_plotindex] + 0.5, - alpha = series[:yfill_alpha], + alpha = series[:fillalpha], extrakw..., ) push!(handles, handle) @@ -601,7 +601,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) if series[:fill_z] !== nothing # the surface colors are different than z-value extrakw[:facecolors] = - py_shading(series[:yfill_color], py_handle_surface(series[:fill_z])) + py_shading(series[:fillcolor], py_handle_surface(series[:fill_z])) extrakw[:shade] = false else extrakw[:cmap] = py_fillcolormap(series) @@ -685,14 +685,14 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) polygons, linewidths = py_thickness_scale(plt, series[:line_width]), edgecolor = py_color(get_line_color(series)), - facecolor = py_color(series[:yfill_color]), + facecolor = py_color(series[:fillcolor]), alpha = get_fillalpha(series), zorder = series[:series_plotindex], ) handle = ax."add_collection3d"(col) # Fix for handle: https://stackoverflow.com/questions/54994600/pyplot-legend-poly3dcollection-object-has-no-attribute-edgecolors2d # It seems there aren't two different alpha values for edge and face - handle._facecolors2d = py_color(series[:yfill_color]) + handle._facecolors2d = py_color(series[:fillcolor]) handle._edgecolors2d = py_color(get_line_color(series)) push!(handles, handle) end @@ -740,7 +740,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = series[:label], zorder = series[:series_plotindex], cmap = py_fillcolormap(series), - alpha = series[:yfill_alpha], + alpha = series[:fillalpha], # edgecolors = (series[:line_width] > 0 ? py_linecolor(series) : "face"), extrakw..., ) @@ -802,7 +802,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # handleSmooth(plt, ax, series, series[:smooth]) # handle area filling - fillrange = series[:yfill_range] + fillrange = series[:fillrange] if fillrange !== nothing && st !== :contour for segment in series_segments(series) i, rng = segment.attr_index, segment.range @@ -1466,7 +1466,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) nseries += 1 clims = get_clims(sp, series) # add a line/marker and a label - if series[:seriestype] === :shape || series[:yfill_range] !== nothing + if series[:seriestype] === :shape || series[:fillrange] !== nothing lc = get_line_color(series, clims) fc = get_fillcolor(series, clims) la = get_line_alpha(series) diff --git a/src/pipeline.jl b/src/pipeline.jl index ced8c383f..2f62e38ff 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -127,7 +127,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::AKW) :seriestype => :path, :x => sx, :y => sy, - :yfill_range => nothing, + :fillrange => nothing, :label => "", :primary => false, ), @@ -176,7 +176,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l kw[:z_extrema] = ze rib = get(kw, :ribbon, default(:ribbon)) - fr = get(kw, :yfill_range, default(:yfill_range)) + fr = get(kw, :fillrange, default(:fillrange)) # map ribbon if it's a Function if rib isa Function kw[:ribbon] = map(rib, kw[:x]) @@ -186,7 +186,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l make_fillrange_from_ribbon(kw) # map fillrange if it's a Function elseif fr !== nothing && fr isa Function - kw[:yfill_range] = map(fr, kw[:x]) + kw[:fillrange] = map(fr, kw[:x]) end end nothing diff --git a/src/recipes.jl b/src/recipes.jl index 4ee9b6c01..7ba13c8d5 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -51,8 +51,8 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ :line_width, :line_style, :line_z, - :yfill_color, - :yfill_alpha, + :fillcolor, + :fillalpha, :fill_z, :marker_color, :marker_alpha, @@ -64,7 +64,7 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ :yerror, :zerror, :series_annotations, - :yfill_range, + :fillrange, ] @nospecialize @@ -82,11 +82,11 @@ const POTENTIAL_VECTOR_ARGUMENTS = [ end # a tuple as fillrange has to be handled differently - if typeof(plotattributes[:yfill_range]) <: Tuple - lower, upper = plotattributes[:yfill_range] + if typeof(plotattributes[:fillrange]) <: Tuple + lower, upper = plotattributes[:fillrange] typeof(lower) <: AVec && (lower = _cycle(lower, indices)) typeof(upper) <: AVec && (upper = _cycle(upper, indices)) - plotattributes[:yfill_range] = (lower, upper) + plotattributes[:fillrange] = (lower, upper) end typeof(z) <: AVec && (z := z[indices]) @@ -218,7 +218,7 @@ make_steps(t::Tuple, st, even) = Tuple(make_steps(ti, st, even) for ti in t) seriestype := :path # handle fillrange - plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :pre, false) + plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :pre, false) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -243,7 +243,7 @@ end seriestype := :path # handle fillrange - plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :post, true) + plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, true) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -268,7 +268,7 @@ end seriestype := :path # handle fillrange - plotattributes[:yfill_range] = make_steps(plotattributes[:yfill_range], :post, false) + plotattributes[:fillrange] = make_steps(plotattributes[:fillrange], :post, false) # create a secondary series for the markers if plotattributes[:marker_shape] !== :none @@ -430,7 +430,7 @@ end end # make fillto a vector... default fills to 0 - if (fillto = plotattributes[:yfill_range]) === nothing + if (fillto = plotattributes[:fillrange]) === nothing fillto = 0 end if yscale in _logScales && !all(_is_positive, fillto) @@ -510,7 +510,7 @@ end y_pts[inds] .= [ye[i], ye[i], ye[i + 1], ye[i + 1], ye[i]] fz[k] = z.surf[i, j] end - ensure_gradient!(plotattributes, :yfill_color, :yfill_alpha) + ensure_gradient!(plotattributes, :fillcolor, :fillalpha) fill_z := fz line_z := fz x := x_pts @@ -1340,7 +1340,7 @@ end yflip --> true colorbar --> false aspect_ratio --> :equal - z, plotattributes[:yfill_color] = replace_image_with_heatmap(mat) + z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) SliceIt, m, n, Surface(z) end end @@ -1405,7 +1405,7 @@ end seriestype := :heatmap yflip --> true colorbar --> false - z, plotattributes[:yfill_color] = replace_image_with_heatmap(mat) + z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat) SliceIt, x, y, Surface(z) end end diff --git a/src/unitful.jl b/src/unitful.jl index 1ac542952..e5552b5d5 100644 --- a/src/unitful.jl +++ b/src/unitful.jl @@ -50,7 +50,7 @@ function fixaxis!(attr, x, axisletter) ustripattribute!(attr, err, u) if axisletter === :y ustripattribute!(attr, :ribbon, u) - ustripattribute!(attr, :yfill_range, u) + ustripattribute!(attr, :fillrange, u) end fixaspectratio!(attr, u, axisletter) fixmarkercolor!(attr) diff --git a/src/utils.jl b/src/utils.jl index 31b0d4d35..29467dccb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -384,8 +384,8 @@ function make_fillrange_from_ribbon(kw::AKW) rib = wraptuple(rib) rib1, rib2 = -first(rib), last(rib) # kw[:ribbon] = nothing - kw[:yfill_range] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) - (get(kw, :yfill_alpha, nothing) === nothing) && (kw[:yfill_alpha] = 0.5) + kw[:fillrange] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) + (get(kw, :fillalpha, nothing) === nothing) && (kw[:fillalpha] = 0.5) end #turn tuple of fillranges to one path @@ -425,7 +425,7 @@ ylims(sp_idx::Int = 1) = ylims(current(), sp_idx) zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) iscontour(series::Series) = series[:seriestype] in (:contour, :contour3d) -isfilledcontour(series::Series) = iscontour(series) && series[:yfill_range] !== nothing +isfilledcontour(series::Series) = iscontour(series) && series[:fillrange] !== nothing function contour_levels(series::Series, clims) iscontour(series) || error("Not a contour series") @@ -438,7 +438,7 @@ function contour_levels(series::Series, clims) levels end -for comp in (:line_, :yfill_, :marker_) +for comp in (:line_, :fill, :marker_) compcolor = string(comp, :color) get_compcolor = Symbol(:get_, compcolor) comp_z = string(comp, :z) @@ -448,7 +448,7 @@ for comp in (:line_, :yfill_, :marker_) @eval begin function $get_compcolor(series, cmin::Real, cmax::Real, i::Int = 1) - c = series[$Symbol($compcolor)] # series[:line_color], series[:yfill_color], series[:marker_color] + c = series[$Symbol($compcolor)] # series[:line_color], series[:fillcolor], series[:marker_color] z = series[$Symbol($comp_z)] # series[:line_z], series[:fill_z], series[:marker_z] if z === nothing isa(c, ColorGradient) ? c : plot_color(_cycle(c, i)) @@ -475,7 +475,7 @@ end function get_colorgradient(series::Series) st = series[:seriestype] if st in (:surface, :heatmap) || isfilledcontour(series) - series[:yfill_color] + series[:fillcolor] elseif st in (:contour, :wireframe) series[:line_color] elseif series[:marker_z] !== nothing @@ -483,7 +483,7 @@ function get_colorgradient(series::Series) elseif series[:line_z] !== nothing series[:line_color] elseif series[:fill_z] !== nothing - series[:yfill_color] + series[:fillcolor] end end @@ -496,7 +496,7 @@ get_gradient(cp::ColorPalette) = cgrad(cp, categorical = true) get_linewidth(series, i::Int = 1) = _cycle(series[:line_width], i) get_linestyle(series, i::Int = 1) = _cycle(series[:line_style], i) -get_fillstyle(series, i::Int = 1) = _cycle(series[:yfill_style], i) +get_fillstyle(series, i::Int = 1) = _cycle(series[:fillstyle], i) function get_markerstrokecolor(series, i::Int = 1) msc = series[:marker_stroke_color] @@ -513,9 +513,9 @@ const _segmenting_vector_attributes = ( :line_alpha, :line_width, :line_style, - :yfill_color, - :yfill_alpha, - :yfill_style, + :fillcolor, + :fillalpha, + :fillstyle, :marker_color, :marker_alpha, :marker_size, diff --git a/test/test_defaults.jl b/test/test_defaults.jl index 3f2a9869c..d96f82152 100644 --- a/test/test_defaults.jl +++ b/test/test_defaults.jl @@ -12,9 +12,9 @@ Plots._plots_theme_defaults() @testset "default" begin default(fillrange = 0) - @test Plots._series_defaults[:yfill_range] == 0 + @test Plots._series_defaults[:fillrange] == 0 pl = plot(1:5) - @test pl[1][1][:yfill_range] == 0 + @test pl[1][1][:fillrange] == 0 @test_nowarn default(legendfont = font(5)) pl = plot(1:5) @test pl[1][:legend_font_pointsize] == 5 diff --git a/test/test_misc.jl b/test/test_misc.jl index dd194bc34..11c26a20b 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -158,7 +158,7 @@ end end @testset "Slicing" begin - @test plot(1:5, fillrange = 0)[1][1][:yfill_range] == 0 + @test plot(1:5, fillrange = 0)[1][1][:fillrange] == 0 data4 = rand(4, 4) mat = reshape(1:8, 2, 4) sp = plot(data4, ribbon = (mat, mat))[1] @@ -287,7 +287,7 @@ with(:gr) do y, z; connections = [ - [1, 2, 4, 3], # Quadrangle + [1, 2, 4, 3], # Quadrangle [1, 2, 5], # Triangle [2, 4, 5], # Triangle [4, 3, 5], # Triangle From 62fee9bdb75993947a751eafc7472b45765e67b4 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 10 Nov 2022 22:35:49 +0100 Subject: [PATCH 13/27] fix docstrings --- src/shorthands.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/shorthands.jl b/src/shorthands.jl index d2dc48a35..954f33708 100644 --- a/src/shorthands.jl +++ b/src/shorthands.jl @@ -7,11 +7,11 @@ Make a scatter plot of `y` vs `x`. # Keyword arguments -- $(_document_argument("markersize")) -- $(_document_argument("markercolor")) -- $(_document_argument("markershape")) -- $(_document_argument("markercolor")) -- $(_document_argument("markeralpha")) +- $(_document_argument("marker_size")) +- $(_document_argument("marker_color")) +- $(_document_argument("marker_shape")) +- $(_document_argument("marker_color")) +- $(_document_argument("marker_alpha")) # Examples ```julia-repl @@ -181,7 +181,7 @@ Draw a stick plot of `y` vs `x`. # Arguments - $(_document_argument("fillrange")) -- $(_document_argument("markershape")) +- $(_document_argument("marker_shape")) # Example ```julia-repl From 65fed0ae888b98999572afb366b0a818fa047f08 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 10 Nov 2022 22:53:11 +0100 Subject: [PATCH 14/27] fix args test --- test/test_args.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_args.jl b/test/test_args.jl index 58e754b05..d22fac2ee 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -1,3 +1,4 @@ +using Plots, Test @testset "Subplot Attributes" begin let pl = plot(rand(4, 4), layout = 2) @test pl[1].primary_series_count == 2 @@ -53,7 +54,7 @@ end ) :aliases = Dict( :legend_position => (:legend, :leg, :key), :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), - :legend_title = (:key_title, :label_title, :leg_title), + :legend_title => (:key_title, :label_title, :leg_title), ) @test Plots._subplot_defaults[:legend_font_family] == :match @test Plots._subplot_defaults[:legend_column] == 1 From f47764d216a1e5d099f75fb59d984ce851c2d3c7 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 11 Nov 2022 00:44:18 +0100 Subject: [PATCH 15/27] fix aliases, fill_z and filter compounds --- src/args.jl | 10 +++++++--- src/components.jl | 2 +- src/utils.jl | 2 +- test/test_axes.jl | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/args.jl b/src/args.jl index 5705891b3..b3cfccb95 100644 --- a/src/args.jl +++ b/src/args.jl @@ -16,7 +16,7 @@ function add_aliases(sym::Symbol, aliases::Symbol...) str2 = replace(str, ga) _keyAliases[Symbol(str2)] = sym end - (haskey(_keyAliases, alias) || alias === sym) && return + (haskey(_keyAliases, alias) || alias === sym) && continue _keyAliases[alias] = sym end nothing @@ -2157,7 +2157,8 @@ macro add_attributes(level, expr, args...) insert_block = Expr(:block) for (key, value) in key_dict - # e.g. _series_defualts[key] = value + @show value + # e.g. _series_defaults[key] = value exp_key = Symbol(lowercase(string(T)), "_", key) pl_key = makeplural(exp_key) if QuoteNode(exp_key) in match_table.args[2].args @@ -2224,7 +2225,10 @@ function _splitdef!(blk, key_dict) continue end defexpr = ei.args[2] # defexpr - key_dict[var] = defexpr + # filter e.g. marker::Marker = Marker(...) + if !(defexpr isa Expr && defexpr.head == :call && defexpr.args[1] == ei.args[1].args[2]) + key_dict[var] = defexpr + end blk.args[i] = lhs elseif ei.head === :(::) && ei.args[1] isa Symbol # var::Typ diff --git a/src/components.jl b/src/components.jl index b8895af27..5b18ceac5 100644 --- a/src/components.jl +++ b/src/components.jl @@ -835,7 +835,7 @@ end :match = ( ) :aliases = Dict( :legend_position => (:legend, :leg, :key), :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), - :legend_foreground_color => (:foreground_legend, :foreground_colour_legend, :foreground_colour_legend) + :legend_foreground_color => (:foreground_legend, :foreground_color_legend, :foreground_colour_legend) ) ### Line diff --git a/src/utils.jl b/src/utils.jl index 29467dccb..a6c2b6301 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -441,7 +441,7 @@ end for comp in (:line_, :fill, :marker_) compcolor = string(comp, :color) get_compcolor = Symbol(:get_, compcolor) - comp_z = string(comp, :z) + comp_z = string(comp, comp === :fill ? :_z : :z) compalpha = string(comp, :alpha) get_compalpha = Symbol(:get_, compalpha) diff --git a/test/test_axes.jl b/test/test_axes.jl index 1b819bdc6..10a08a2d2 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -1,3 +1,4 @@ +using Plots, Test @testset "Axes" begin pl = plot() axis = pl.subplots[1][:xaxis] @@ -124,7 +125,7 @@ end @testset "Axis-aliases" begin @test haskey(Plots._keyAliases, :xguideposition) @test haskey(Plots._keyAliases, :x_guide_position) - @test !haskey(Plots._keyAliases, :xguide_position) + @test haskey(Plots._keyAliases, :xguide_position) pl = plot(1:2, xl = "x label") @test pl[1][:xaxis][:guide] === "x label" pl = plot(1:2, xrange = (0, 3)) @@ -150,7 +151,7 @@ end end @testset "Aliases" begin - compare(pl::Plot, s::Symbol, val, op) = + compare(pl::Plots.Plot, s::Symbol, val, op) = op(pl[1][:xaxis][s], val) && op(pl[1][:yaxis][s], val) && op(pl[1][:zaxis][s], val) pl = plot(1:2, guide = "all labels") @test compare(pl, :guide, "all labels", ===) From 719f4b0d908d6c5b6fe269290b8e5f79728a9e4f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 11 Nov 2022 14:56:13 +0100 Subject: [PATCH 16/27] cosmetics --- RecipesPipeline/src/api.jl | 2 +- src/args.jl | 1 - src/pipeline.jl | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RecipesPipeline/src/api.jl b/RecipesPipeline/src/api.jl index 3ff927d3b..bc810ea52 100644 --- a/RecipesPipeline/src/api.jl +++ b/RecipesPipeline/src/api.jl @@ -5,7 +5,7 @@ """ warn_on_recipe_aliases!(plt, plotattributes, recipe_type, args...) -Warn if an alias is dedected in `plotattributes` after a recipe of type `recipe_type` is +Warn if an alias is detected in `plotattributes` after a recipe of type `recipe_type` is applied to 'args'. `recipe_type` is either `:user`, `:type`, `:plot` or `:series`. """ function warn_on_recipe_aliases!( diff --git a/src/args.jl b/src/args.jl index b3cfccb95..bd76a2668 100644 --- a/src/args.jl +++ b/src/args.jl @@ -2157,7 +2157,6 @@ macro add_attributes(level, expr, args...) insert_block = Expr(:block) for (key, value) in key_dict - @show value # e.g. _series_defaults[key] = value exp_key = Symbol(lowercase(string(T)), "_", key) pl_key = makeplural(exp_key) diff --git a/src/pipeline.jl b/src/pipeline.jl index 2f62e38ff..802db3a16 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -10,7 +10,8 @@ function RecipesPipeline.warn_on_recipe_aliases!( ) pkeys = keys(plotattributes) for k in pkeys - if (dk = get(_keyAliases, k, nothing)) !== nothing + dk = get(_keyAliases, k, nothing) + if dk !== nothing kv = RecipesPipeline.pop_kw!(plotattributes, k) dk ∈ pkeys || (plotattributes[dk] = kv) end From 38806ac593d44e841365a965a41b5eb2bd73097c Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 11 Nov 2022 15:02:35 +0100 Subject: [PATCH 17/27] fix marker aliases in shapes --- src/consts.jl | 2 ++ src/recipes.jl | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/consts.jl b/src/consts.jl index 85667b9df..fa3406ae3 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -69,6 +69,8 @@ const _all_plot_args = _plot_args const _all_args = union(_lettered_all_axis_args, _all_subplot_args, _all_series_args, _all_plot_args) +const _all_segmenting_attributes = Set(_segmenting_vector_attributes ∪ _segmenting_array_attributes ∪ reduce(vcat, aliases.(_segmenting_array_attributes)) ∪ reduce(vcat, aliases.(_segmenting_vector_attributes))) + # add all pluralized forms to the _keyAliases dict for arg in _all_args add_aliases(arg, makeplural(arg)) diff --git a/src/recipes.jl b/src/recipes.jl index 7ba13c8d5..94fafcbaa 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -463,6 +463,7 @@ end # reset orientation orientation := default(:orientation) + @show RecipesPipeline.explicitkeys(plotattributes) # draw the bar shapes @series begin seriestype := :shape @@ -471,7 +472,7 @@ end x := xseg.pts y := yseg.pts # expand attributes to match indices in new series data - for k in _segmenting_vector_attributes ∪ _segmenting_array_attributes + for k in _all_segmenting_attributes if (v = get(plotattributes, k, nothing)) isa AVec if eachindex(v) != eachindex(y) @warn "Indices $(eachindex(v)) of attribute `$k` do not match data indices $(eachindex(y))." @@ -492,6 +493,7 @@ end fillrange := nothing x := x y := y + @show plotattributes () end @deps bar shape @@ -1356,7 +1358,7 @@ end seriestype --> :shape # For backwards compatibility, column vectors of segmenting attributes are # interpreted as having one element per shape - for attr in union(_segmenting_array_attributes, _segmenting_vector_attributes) + for attr in _all_segmenting_attributes v = get(plotattributes, attr, nothing) if v isa AVec || v isa AMat && size(v, 2) == 1 @warn """ From 5e1bd5e56abc7f9a1734d4f0fa2f81e43a5647d0 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 6 Jan 2023 22:49:43 +0100 Subject: [PATCH 18/27] wrap attributes in Attributes --- src/components.jl | 21 +++++++++++++++++++++ src/plot.jl | 2 +- src/recipes.jl | 2 -- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components.jl b/src/components.jl index 5b18ceac5..d3da89bb3 100644 --- a/src/components.jl +++ b/src/components.jl @@ -11,6 +11,27 @@ nanappend!(a::AVec{P3}, b) = (push!(a, (NaN, NaN, NaN)); append!(a, b); nothing) compute_angle(v::P2) = (angle = atan(v[2], v[1]); angle < 0 ? 2π - angle : angle) +struct Attributes <: AbstractDict{Symbol, Any} + plotattributes::KW +end + +function Base.get(attr::Attributes, key, default) + get(attr.plotattributes, get(_keyAliases, key, key), default) +end + +function Base.setindex!(attr::Attributes, key, value) + if key === :seriestype + value = get(_typeAliases, value, value) + end + setindex!(attr.plotattributes, get(_keyAliases, key, key), value) +end + +Base.iterate(attr::Attributes, args...; kwargs...) = iterate(attr.plotattributes, args...; kwargs...) +Base.delete!(attr::Attributes, key) = delete!(attr.plotattributes, key) +Base.length(attr::Attributes) = length(attr.plotattributes) +Base.keys(attr::Attributes) = keys(attr.plotattributes) +Base.values(attr::Attributes) = values(attr.plotattributes) + # ------------------------------------------------------------- struct Shape{X<:Number,Y<:Number} diff --git a/src/plot.jl b/src/plot.jl index b5c20feb2..161debdfd 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -222,7 +222,7 @@ end # note: at entry, we only have those preprocessed args which were passed in... no default values yet function _plot!(plt::Plot, plotattributes, args) @nospecialize - RecipesPipeline.recipe_pipeline!(plt, plotattributes, args) + RecipesPipeline.recipe_pipeline!(plt, Attributes(plotattributes), args) current(plt) _do_plot_show(plt, plt[:show]) return plt diff --git a/src/recipes.jl b/src/recipes.jl index 94fafcbaa..13e14f492 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -463,7 +463,6 @@ end # reset orientation orientation := default(:orientation) - @show RecipesPipeline.explicitkeys(plotattributes) # draw the bar shapes @series begin seriestype := :shape @@ -493,7 +492,6 @@ end fillrange := nothing x := x y := y - @show plotattributes () end @deps bar shape From 65116fbb4e3bd78ef64e0439b5aefc202560e32b Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Sun, 15 Jan 2023 17:04:45 +0100 Subject: [PATCH 19/27] move alias detection to DefaultDict --- RecipesPipeline/src/RecipesPipeline.jl | 1 + RecipesPipeline/src/api.jl | 12 ++++-- RecipesPipeline/src/plot_recipe.jl | 1 - RecipesPipeline/src/series_recipe.jl | 3 +- RecipesPipeline/src/utils.jl | 53 ++++++++++++++++++++------ RecipesPipeline/test/runtests.jl | 5 ++- src/axes.jl | 4 +- src/backends/hdf5.jl | 2 +- src/components.jl | 21 ---------- src/consts.jl | 2 +- src/pipeline.jl | 3 +- src/plot.jl | 2 +- src/types.jl | 4 +- test/test_recipes.jl | 7 ++++ 14 files changed, 72 insertions(+), 48 deletions(-) diff --git a/RecipesPipeline/src/RecipesPipeline.jl b/RecipesPipeline/src/RecipesPipeline.jl index 0262d0e62..a1c299933 100644 --- a/RecipesPipeline/src/RecipesPipeline.jl +++ b/RecipesPipeline/src/RecipesPipeline.jl @@ -38,6 +38,7 @@ export warn_on_recipe_aliases, get_axis_limits, is_axis_attribute, type_alias, + key_alias, plot_setup!, slice_series_attributes!, process_sliced_series_attributes! diff --git a/RecipesPipeline/src/api.jl b/RecipesPipeline/src/api.jl index bc810ea52..dae1bb9e6 100644 --- a/RecipesPipeline/src/api.jl +++ b/RecipesPipeline/src/api.jl @@ -155,12 +155,18 @@ get_axis_limits(plt, letter) = throw(ErrorException("Axis limits not defined.")) # ## Plot recipes """ - type_alias(plt, st) + type_alias(typeof(plt), st) -Return the seriestype alias for `st`. +Return the canonical seriestype for `st`. """ -type_alias(plt, st) = st +type_alias(plt::Type{<:Any}, st) = st +""" + key_alias(typeof(plt), key) + +Return the canonical key for `key`. +""" +key_alias(plt::Type{<:Any}, key) = key # ## Plot setup """ diff --git a/RecipesPipeline/src/plot_recipe.jl b/RecipesPipeline/src/plot_recipe.jl index 8cddfbd70..e5372677c 100644 --- a/RecipesPipeline/src/plot_recipe.jl +++ b/RecipesPipeline/src/plot_recipe.jl @@ -27,7 +27,6 @@ function _process_plotrecipe(plt, kw, kw_list, still_to_process) return end st = kw[:seriestype] - st = kw[:seriestype] = type_alias(plt, st) datalist = RecipesBase.apply_recipe(kw, Val{st}, plt) if !isnothing(datalist) warn_on_recipe_aliases!(plt, datalist, :plot, st) diff --git a/RecipesPipeline/src/series_recipe.jl b/RecipesPipeline/src/series_recipe.jl index bb4275803..d5a38ece3 100644 --- a/RecipesPipeline/src/series_recipe.jl +++ b/RecipesPipeline/src/series_recipe.jl @@ -15,7 +15,7 @@ function _process_seriesrecipes!(plt, kw_list) end process_sliced_series_attributes!(plt, kw_list) for kw in kw_list - series_attr = DefaultsDict(kw, series_defaults(plt)) + series_attr = DefaultsDict(typeof(plt), kw, series_defaults(plt)) # now we have a fully specified series, with colors chosen. we must recursively # handle series recipes, which dispatch on seriestype. If a backend does not # natively support a seriestype, we check for a recipe that will convert that @@ -33,7 +33,6 @@ end function _process_seriesrecipe(plt, plotattributes) # replace seriestype aliases st = Symbol(plotattributes[:seriestype]) - st = plotattributes[:seriestype] = type_alias(plt, st) # shapes shouldn't have fillrange set if plotattributes[:seriestype] == :shape diff --git a/RecipesPipeline/src/utils.jl b/RecipesPipeline/src/utils.jl index 682b91d01..65df728e3 100644 --- a/RecipesPipeline/src/utils.jl +++ b/RecipesPipeline/src/utils.jl @@ -9,28 +9,47 @@ const AKW = AbstractDict{Symbol,Any} # ## DefaultsDict # -------------------------------- -struct DefaultsDict <: AbstractDict{Symbol,Any} +struct DefaultsDict{P} <: AbstractDict{Symbol,Any} + plot_type::Type{P} explicit::KW defaults::KW + function DefaultsDict{P}(plot_type::Type{P}, explicit::KW, defaults::KW) where P + e = KW( key_alias(plot_type, k) => v === :seriestype ? type_alias(plot_type, v) : v for (k, v) in explicit) + new{P}(plot_type, e, defaults) + end end -Base.merge(d1::DefaultsDict, d2::DefaultsDict) = - DefaultsDict(merge(d1.explicit, d2.explicit), merge(d1.defaults, d2.defaults)) -Base.getindex(dd::DefaultsDict, k) = +DefaultsDict(pt, e, d) = DefaultsDict{pt}(pt, e, d) +function Base.merge(d1::DefaultsDict, d2::DefaultsDict) + @assert d1.plot_type === d2.plot_type + DefaultsDict(d1.plot_type, merge(d1.explicit, d2.explicit), merge(d1.defaults, d2.defaults)) +end +function Base.getindex(dd::DefaultsDict, k) + k = key_alias(dd.plot_type, k) if haskey(dd.explicit, k) dd.explicit[k] else dd.defaults[k] end -Base.haskey(dd::DefaultsDict, k) = haskey(dd.explicit, k) || haskey(dd.defaults, k) -Base.get(dd::DefaultsDict, k, default) = haskey(dd, k) ? dd[k] : default -Base.get!(dd::DefaultsDict, k, default) = +end +function Base.haskey(dd::DefaultsDict, k) + k = key_alias(dd.plot_type, k) + haskey(dd.explicit, k) || haskey(dd.defaults, k) +end +function Base.get(dd::DefaultsDict, k, default) + k = key_alias(dd.plot_type, k) + haskey(dd, k) ? dd[k] : default +end +function Base.get!(dd::DefaultsDict, k, default) + k = key_alias(dd.plot_type, k) if haskey(dd, k) dd[k] else dd.defaults[k] = default end +end function Base.delete!(dd::DefaultsDict, k) + k = key_alias(dd.plot_type, k) haskey(dd.explicit, k) && delete!(dd.explicit, k) haskey(dd.defaults, k) && delete!(dd.defaults, k) dd @@ -46,12 +65,24 @@ function Base.iterate(dd::DefaultsDict, (key_list, i)) (k => dd[k], (key_list, i + 1)) end -Base.copy(dd::DefaultsDict) = DefaultsDict(copy(dd.explicit), dd.defaults) +Base.copy(dd::DefaultsDict) = DefaultsDict(dd.plot_type, copy(dd.explicit), dd.defaults) -RecipesBase.is_explicit(dd::DefaultsDict, k) = haskey(dd.explicit, k) -RecipesBase.is_default(dd::DefaultsDict, k) = !is_explicit(dd, k) && haskey(dd.defaults, k) +function RecipesBase.is_explicit(dd::DefaultsDict, k) + k = key_alias(dd.plot_type, k) + haskey(dd.explicit, k) +end +function RecipesBase.is_default(dd::DefaultsDict, k) + k = key_alias(dd.plot_type, k) + !is_explicit(dd, k) && haskey(dd.defaults, k) +end -Base.setindex!(dd::DefaultsDict, v, k) = dd.explicit[k] = v +function Base.setindex!(dd::DefaultsDict, v, k) + k = key_alias(dd.plot_type, k) + if k === :seriestype + v = type_alias(dd.plot_type, v) + end + dd.explicit[k] = v +end # Reset to default value and return dict function reset_kw!(dd::DefaultsDict, k) diff --git a/RecipesPipeline/test/runtests.jl b/RecipesPipeline/test/runtests.jl index fcdff96f7..a05b112a4 100644 --- a/RecipesPipeline/test/runtests.jl +++ b/RecipesPipeline/test/runtests.jl @@ -7,7 +7,7 @@ import RecipesPipeline: _prepare_series_data import RecipesBase @testset "DefaultsDict" begin - dd = DefaultsDict(Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) + dd = DefaultsDict(Plots.Plot, Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) @test all(explicitkeys(dd) .== [:bar, :foo]) @test all(defaultkeys(dd) .== [:baz, :foo]) @@ -44,7 +44,8 @@ end @test !is_axis_attribute(plt, :foo) @test process_userrecipe!(plt, [:foo], :bar) == [:foo, :bar] - @test type_alias(plt, :wireframe) ≡ :wireframe + @test type_alias(typeof(plt), :wireframe) ≡ :wireframe + @test key_alias(typeof(plt), :label) ≡ :label @test plot_setup!(plt, plotattributes, kw_list) isa Nothing @test slice_series_attributes!(plt, kw_list, kw) isa Nothing diff --git a/src/axes.jl b/src/axes.jl index 3f6470aa7..d89a83c5e 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -16,7 +16,7 @@ function Axis(sp::Subplot, letter::Symbol, args...; kw...) :show => true, # show or hide the axis? (useful for linked subplots) ) - attr = DefaultsDict(explicit, _axis_defaults_byletter[letter]) + attr = DefaultsDict(Plots.Plot, explicit, _axis_defaults_byletter[letter]) # update the defaults attr!(Axis([sp], attr), args...; kw...) @@ -512,7 +512,7 @@ end scale_lims!([plt], [letter], factor) Scale the limits of the axis specified by `letter` (one of `:x`, `:y`, `:z`) by the -given `factor` around the limits' middle point. +given `factor` around the limits' middle point. If `letter` is omitted, all axes are affected. """ function scale_lims!(sp::Subplot, letter, factor) diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index c81c5690b..f2e220ec5 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -426,7 +426,7 @@ end # 1st arg appears to be ref to subplots. Seems to work without it. _read(::Type{Axis}, grp::Group) = - Axis([], DefaultsDict(_read(KW, grp["plotattributes"]), _axis_defaults)) + Axis([], DefaultsDict(Plots.Plot, _read(KW, grp["plotattributes"]), _axis_defaults)) # Not for use in main "Plot.subplots[]" hierarchy. Just establishes reference with subplot_index. _read(::Type{Subplot}, grp::Group) = diff --git a/src/components.jl b/src/components.jl index d3da89bb3..5b18ceac5 100644 --- a/src/components.jl +++ b/src/components.jl @@ -11,27 +11,6 @@ nanappend!(a::AVec{P3}, b) = (push!(a, (NaN, NaN, NaN)); append!(a, b); nothing) compute_angle(v::P2) = (angle = atan(v[2], v[1]); angle < 0 ? 2π - angle : angle) -struct Attributes <: AbstractDict{Symbol, Any} - plotattributes::KW -end - -function Base.get(attr::Attributes, key, default) - get(attr.plotattributes, get(_keyAliases, key, key), default) -end - -function Base.setindex!(attr::Attributes, key, value) - if key === :seriestype - value = get(_typeAliases, value, value) - end - setindex!(attr.plotattributes, get(_keyAliases, key, key), value) -end - -Base.iterate(attr::Attributes, args...; kwargs...) = iterate(attr.plotattributes, args...; kwargs...) -Base.delete!(attr::Attributes, key) = delete!(attr.plotattributes, key) -Base.length(attr::Attributes) = length(attr.plotattributes) -Base.keys(attr::Attributes) = keys(attr.plotattributes) -Base.values(attr::Attributes) = values(attr.plotattributes) - # ------------------------------------------------------------- struct Shape{X<:Number,Y<:Number} diff --git a/src/consts.jl b/src/consts.jl index fa3406ae3..38f547d2c 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -69,7 +69,7 @@ const _all_plot_args = _plot_args const _all_args = union(_lettered_all_axis_args, _all_subplot_args, _all_series_args, _all_plot_args) -const _all_segmenting_attributes = Set(_segmenting_vector_attributes ∪ _segmenting_array_attributes ∪ reduce(vcat, aliases.(_segmenting_array_attributes)) ∪ reduce(vcat, aliases.(_segmenting_vector_attributes))) +const _all_segmenting_attributes = Set(_segmenting_vector_attributes ∪ _segmenting_array_attributes) # add all pluralized forms to the _keyAliases dict for arg in _all_args diff --git a/src/pipeline.jl b/src/pipeline.jl index 802db3a16..01873928b 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -141,8 +141,9 @@ RecipesPipeline.get_axis_limits(plt::Plot, letter) = axis_limits(plt[1], letter, ## Plot recipes -RecipesPipeline.type_alias(plt::Plot, st) = get(_typeAliases, st, st) +RecipesPipeline.type_alias(pt::Type{<:Plots.Plot}, st) = get(_typeAliases, st, st) +RecipesPipeline.key_alias(pt::Type{<:Plots.Plot}, key) = get(_keyAliases, key, key) ## Plot setup function RecipesPipeline.plot_setup!(plt::Plot, plotattributes, kw_list) diff --git a/src/plot.jl b/src/plot.jl index 161debdfd..b5c20feb2 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -222,7 +222,7 @@ end # note: at entry, we only have those preprocessed args which were passed in... no default values yet function _plot!(plt::Plot, plotattributes, args) @nospecialize - RecipesPipeline.recipe_pipeline!(plt, Attributes(plotattributes), args) + RecipesPipeline.recipe_pipeline!(plt, plotattributes, args) current(plt) _do_plot_show(plt, plt[:show]) return plt diff --git a/src/types.jl b/src/types.jl index 4d10c8977..7843c4c5e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -38,7 +38,7 @@ mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout defaultminpad, defaultbox, defaultbox, - DefaultsDict(KW(), _subplot_defaults), + DefaultsDict(T, KW(), _subplot_defaults), nothing, nothing, ) @@ -76,7 +76,7 @@ mutable struct Plot{T<:AbstractBackend} <: AbstractPlot{T} new{typeof(be)}( be, 0, - DefaultsDict(KW(), _plot_defaults), + DefaultsDict(Plots.Plot{typeof(be)}, KW(), _plot_defaults), Series[], nothing, Subplot[], diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 0e14f1ecc..5b1b51b58 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -124,3 +124,10 @@ with(:gr) do show(devnull, bar([1 2 3], [0.02 125 10_000]; yscale = :log10)) end end + +@testset "Bar" begin + pl = bar(["a", "b", "c"], [1,2,3]) + @test pl[1][2][:marker_size] == 0 + @test pl[1][2][:marker_alpha] == 0 + @test pl[1][1][:line_color] == RGBA{Float64}(0.0,0.0,0.0,1.0) +end From 867afa01e0fabbd72709a364ceea6437545f2d22 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 8 Mar 2023 16:25:50 +0100 Subject: [PATCH 20/27] add test --- test/test_args.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_args.jl b/test/test_args.jl index d22fac2ee..d7f4b1703 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -34,6 +34,7 @@ end @test yticks(pl2) == xticks(pl1) @test filter(isfinite, pl1[1][1][:x]) == filter(isfinite, pl2[1][1][:y]) @test filter(isfinite, pl1[1][1][:y]) == filter(isfinite, pl2[1][1][:x]) + @test pl1[1][1][:line_color] == RGBA{Float64}(0.0,0.0,0.0,1.0) end @testset "@add_attributes" begin From bffd24d7231ecd4044533993bde7025be0f10025 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 9 Mar 2023 11:40:14 +0100 Subject: [PATCH 21/27] make it precompile --- src/args.jl | 10 +++------- src/backends/deprecated/pgfplots.jl | 4 ++-- src/backends/deprecated/pyplot.jl | 20 ++++++++++---------- src/backends/gaston.jl | 4 ++-- src/backends/gr.jl | 14 +++++++------- src/backends/pgfplotsx.jl | 12 ++++++------ src/backends/plotly.jl | 8 ++++---- src/backends/pythonplot.jl | 20 ++++++++++---------- src/types.jl | 6 +++--- src/utils.jl | 10 +++++----- 10 files changed, 52 insertions(+), 56 deletions(-) diff --git a/src/args.jl b/src/args.jl index 381310ae6..14987b1d8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1483,7 +1483,7 @@ function warn_on_unsupported_args(pkg::AbstractBackend, plotattributes) Set{Symbol}() end extra_kwargs = Dict{Symbol,Any}() - for k in explicitkeys(plotattributes) + for k in RecipesPipeline.explicitkeys(plotattributes) (is_attr_supported(pkg, k) && k ∉ keys(_deprecated_attributes)) && continue k in _suppress_warnings && continue if ismissing(default(k)) @@ -1948,13 +1948,9 @@ ensure_gradient!(plotattributes::AKW, csym::Symbol, asym::Symbol) = const DEFAULT_LINEWIDTH = Ref(1) # get a good default linewidth... 0 for surface and heatmaps - if plotattributes[:line_width] === :auto - plotattributes[:line_width] = ( - get(plotattributes, :seriestype, :path) in (:surface, :heatmap, :image) ? 0 : 1 - ) _replace_linewidth(plotattributes::AKW) = - if plotattributes[:linewidth] === :auto - plotattributes[:linewidth] = + if plotattributes[:line_width] === :auto + plotattributes[:line_width] = (get(plotattributes, :seriestype, :path) ∉ (:surface, :heatmap, :image)) * DEFAULT_LINEWIDTH[] end diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 780ecf748..f9043b1bc 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -106,10 +106,10 @@ function pgf_linestyle(linewidth::Real, color, α = 1, linestyle = "solid") end function pgf_linestyle(plotattributes, i = 1) - lw = pgf_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i) + lw = pgf_thickness_scaling(plotattributes) * get_line_width(plotattributes, i) lc = get_line_color(plotattributes, i) la = get_line_alpha(plotattributes, i) - ls = get_linestyle(plotattributes, i) + ls = get_line_style(plotattributes, i) return pgf_linestyle(lw, lc, la, ls) end diff --git a/src/backends/deprecated/pyplot.jl b/src/backends/deprecated/pyplot.jl index b1466ecf4..4819a43dd 100644 --- a/src/backends/deprecated/pyplot.jl +++ b/src/backends/deprecated/pyplot.jl @@ -430,8 +430,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) single_color(get_line_color(series, clims, i)), get_line_alpha(series, i), ), - linewidth = py_thickness_scale(plt, get_linewidth(series, i)), - linestyle = py_linestyle(st, get_linestyle(series, i)), + linewidth = py_thickness_scale(plt, get_line_width(series, i)), + linestyle = py_linestyle(st, get_line_style(series, i)), solid_capstyle = "butt", dash_capstyle = "butt", drawstyle = py_stepstyle(st), @@ -450,8 +450,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) :shrinkB => 0, :edgecolor => py_color(get_line_color(series)), :facecolor => py_color(get_line_color(series)), - :line_width => py_thickness_scale(plt, get_linewidth(series)), - :line_style => py_linestyle(st, get_linestyle(series)), + :line_width => py_thickness_scale(plt, get_line_width(series)), + :line_style => py_linestyle(st, get_line_style(series)), ) add_arrows(x, y) do xyprev, xy ax."annotate"( @@ -735,7 +735,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) fc = get_fillcolor(series, clims, i) la = get_line_alpha(series, i) fa = get_fillalpha(series, i) - ls = get_linestyle(series, i) + ls = get_line_style(series, i) fs = get_fillstyle(series, i) has_fs = !isnothing(fs) @@ -748,7 +748,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) zorder = series[:series_plotindex], edgecolor = py_color(lc, la), facecolor = py_color(fc, has_fs ? 0 : fa), - linewidth = py_thickness_scale(plt, get_linewidth(series, i)), + linewidth = py_thickness_scale(plt, get_line_width(series, i)), linestyle = py_linestyle(st, ls), fill = !has_fs, ) @@ -1452,7 +1452,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) fc = get_fillcolor(series, clims) la = get_line_alpha(series) fa = get_fillalpha(series) - ls = get_linestyle(series) + ls = get_line_style(series) fs = get_fillstyle(series) has_fs = !isnothing(fs) @@ -1460,7 +1460,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) line_handle = pypatches."Patch"( edgecolor = py_color(single_color(lc), la), facecolor = py_color(single_color(fc), has_fs ? 0 : fa), - linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), + linewidth = py_thickness_scale(plt, clamp(get_line_width(series), 0, 5)), linestyle = py_linestyle(series[:seriestype], ls), capstyle = "butt", ) @@ -1484,7 +1484,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) end elseif series[:seriestype] in (:path, :straightline, :scatter, :steppre, :stepmid, :steppost) - has_line = get_linewidth(series) > 0 + has_line = get_line_width(series) > 0 handle = PyPlot.plt."Line2D"( (0, 1), (0, 0), @@ -1496,7 +1496,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) plt, has_line * sp[:legend_font_pointsize] / 8, ), - linestyle = py_linestyle(:path, get_linestyle(series)), + linestyle = py_linestyle(:path, get_line_style(series)), solid_capstyle = "butt", solid_joinstyle = "miter", dash_capstyle = "butt", diff --git a/src/backends/gaston.jl b/src/backends/gaston.jl index 8611bfa4d..e56fde6c5 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -660,8 +660,8 @@ gaston_alpha(alpha) = alpha === nothing ? 0 : alpha gaston_lc_ls_lw(series::Series, clims, i::Int) = ( gaston_color(get_line_color(series, clims, i), get_line_alpha(series, i)), - gaston_linestyle(get_linestyle(series, i)), - get_linewidth(series, i), + gaston_linestyle(get_line_style(series, i)), + get_line_width(series, i), ) gaston_mk_ms_mc(series::Series, clims, i::Int) = ( diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 6f8bcbecc..427aaa07c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -588,8 +588,8 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, vp::GRViewport) series = cbar.lines gr_set_gradient(_cbar_unique(get_colorgradient.(series), "color")) gr_set_line( - _cbar_unique(get_linewidth.(series), "line width"), - _cbar_unique(get_linestyle.(series), "line style"), + _cbar_unique(get_line_width.(series), "line width"), + _cbar_unique(get_line_style.(series), "line style"), _cbar_unique(get_line_color.(series, Ref(clims)), "line color"), sp, ) @@ -1061,7 +1061,7 @@ function gr_add_legend(sp, leg, viewport_area) gr_polyline(x, y, GR.fillarea) lc = get_line_color(series, clims) gr_set_transparency(lc, get_line_alpha(series)) - gr_set_line(get_linewidth(series), get_linestyle(series), lc, sp) + gr_set_line(get_line_width(series), get_line_style(series), lc, sp) gr_set_transparency(lc, la) gr_set_line(clamped_lw, ls, lc, sp) st === :shape && gr_polyline(x, y) @@ -1802,7 +1802,7 @@ function gr_draw_segments(series, x, y, z, fillrange, clims) GR.fillarea(fx, fy) end (lc = get_line_color(series, clims, i)) |> gr_set_fillcolor - gr_set_line(get_linewidth(series, i), get_linestyle(series, i), lc, series) + gr_set_line(get_line_width(series, i), get_line_style(series, i), lc, series) gr_set_transparency(lc, get_line_alpha(series, i)) if is3d GR.polyline3d(x[rng], y[rng], z[rng]) @@ -1873,7 +1873,7 @@ function gr_draw_shapes(series, clims) # draw the shapes lc = get_line_color(series, clims, i) - gr_set_line(get_linewidth(series, i), get_linestyle(series, i), lc, series) + gr_set_line(get_line_width(series, i), get_line_style(series, i), lc, series) gr_set_transparency(lc, get_line_alpha(series, i)) GR.polyline(xseg, yseg) end @@ -1883,7 +1883,7 @@ end function gr_draw_contour(series, x, y, z, clims) GR.setprojectiontype(0) GR.setspace(clims[1], clims[2], 0, 90) - gr_set_line(get_linewidth(series), get_linestyle(series), get_line_color(series), series) + gr_set_line(get_line_width(series), get_line_style(series), get_line_color(series), series) gr_set_transparency(get_fillalpha(series)) h = gr_contour_levels(series, clims) if series[:fillrange] !== nothing @@ -1949,7 +1949,7 @@ function gr_draw_surface(series, x, y, z, clims) end fillalpha = get_fillalpha(series) facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor) - GR.setborderwidth(get_linewidth(series)) + GR.setborderwidth(get_line_width(series)) GR.setbordercolorind(gr_getcolorind(get_line_color(series))) GR.polygonmesh3d(x, y, z, vcat(cns...), signed.(gr_color.(facecolor))) else diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index e6836b35f..0dc8288f6 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -646,8 +646,8 @@ pgfx_series_arguments(series, opt) = opt[:x], opt[:y] end -pgfx_get_linestyle(k::AbstractString) = pgfx_get_linestyle(Symbol(k)) -pgfx_get_linestyle(k::Symbol) = get( +pgfx_get_line_style(k::AbstractString) = pgfx_get_line_style(Symbol(k)) +pgfx_get_line_style(k::Symbol) = get( ( solid = "solid", dash = "dashed", @@ -883,7 +883,7 @@ function pgfx_linestyle(linewidth::Real, color, α = 1, linestyle = :solid) "color" => cstr, "draw opacity" => alpha(cstr), "line width" => linewidth, - pgfx_get_linestyle(linestyle) => nothing, + pgfx_get_line_style(linestyle) => nothing, ) end @@ -891,10 +891,10 @@ pgfx_legend_col(s::Symbol) = s === :horizontal ? -1 : 1 pgfx_legend_col(n) = n function pgfx_linestyle(plotattributes, i = 1) - lw = pgfx_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i) + lw = pgfx_thickness_scaling(plotattributes) * get_line_width(plotattributes, i) lc = single_color(get_line_color(plotattributes, i)) la = get_line_alpha(plotattributes, i) - ls = get_linestyle(plotattributes, i) + ls = get_line_style(plotattributes, i) return pgfx_linestyle(lw, lc, la, ls) end @@ -962,7 +962,7 @@ function pgfx_marker(plotattributes, i = 1) else 0 end, - pgfx_get_linestyle(_cycle(plotattributes[:marker_stroke_style], i)) => + pgfx_get_line_style(_cycle(plotattributes[:marker_stroke_style], i)) => nothing, ), ) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 485d97916..c760b90bb 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -770,8 +770,8 @@ function plotly_series_shapes(plt::Plot, series::Series, clims) :color => rgba_string( plot_color(get_line_color(series, clims, i), get_line_alpha(series, i)), ), - :width => get_linewidth(series, i), - :dash => string(get_linestyle(series, i)), + :width => get_line_width(series, i), + :dash => string(get_line_style(series, i)), ) end plotattributes_out[:showlegend] = k == 1 ? should_add_to_legend(series) : false @@ -896,7 +896,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z :color => rgba_string( plot_color(get_line_color(series, clims, i), get_line_alpha(series, i)), ), - :width => get_linewidth(series, i), + :width => get_line_width(series, i), :shape => if st === :steppre "vh" elseif st === :stepmid @@ -906,7 +906,7 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z else "linear" end, - :dash => string(get_linestyle(series, i)), + :dash => string(get_line_style(series, i)), ) end diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index 02fb4e207..c4c06a755 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -366,8 +366,8 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) # some defaults cbar_scale = sp[:colorbar_scale] - linewidths = linewidth = _py_thickness_scale(plt, get_linewidth(series)) - linestyles = linestyle = _py_linestyle(st, get_linestyle(series)) + linewidths = linewidth = _py_thickness_scale(plt, get_line_width(series)) + linestyles = linestyle = _py_linestyle(st, get_line_style(series)) edgecolor = edgecolors = _py_color(get_linecolor(series, 1, cbar_scale)) facecolor = facecolors = _py_color(series[:fillcolor]) zorder = series[:series_plotindex] @@ -385,8 +385,8 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) single_color(get_linecolor(series, clims, i, cbar_scale)), get_linealpha(series, i), ), - linewidth = _py_thickness_scale(plt, get_linewidth(series, i)), - linestyle = _py_linestyle(st, get_linestyle(series, i)), + linewidth = _py_thickness_scale(plt, get_line_width(series, i)), + linestyle = _py_linestyle(st, get_line_style(series, i)), solid_capstyle = "butt", dash_capstyle = "butt", drawstyle = _py_stepstyle(st), @@ -458,7 +458,7 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) fc = get_fillcolor(series, clims, i) la = get_linealpha(series, i) fa = get_fillalpha(series, i) - ls = get_linestyle(series, i) + ls = get_line_style(series, i) fs = get_fillstyle(series, i) has_fs = !isnothing(fs) @@ -471,7 +471,7 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) path; edgecolor = _py_color(lc, la), facecolor = _py_color(fc, has_fs ? 0 : fa), - linewidth = _py_thickness_scale(plt, get_linewidth(series, i)), + linewidth = _py_thickness_scale(plt, get_line_width(series, i)), linestyle = _py_linestyle(st, ls), fill = !has_fs, zorder, @@ -1341,7 +1341,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) fc = get_fillcolor(series, clims) la = get_linealpha(series) fa = get_fillalpha(series) - ls = get_linestyle(series) + ls = get_line_style(series) fs = get_fillstyle(series) has_fs = !isnothing(fs) @@ -1349,7 +1349,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) mpl.patches.Patch( edgecolor = _py_color(single_color(lc), la), facecolor = _py_color(single_color(fc), has_fs ? 0 : fa), - linewidth = _py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), + linewidth = _py_thickness_scale(plt, clamp(get_line_width(series), 0, 5)), linestyle = _py_linestyle(series[:seriestype], ls), capstyle = "butt", ) |> push_h @@ -1369,7 +1369,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) capstyle = "butt", ) |> push_h elseif series[:seriestype] ∈ _py_legend_series - has_line = get_linewidth(series) > 0 + has_line = get_line_width(series) > 0 PythonPlot.pyplot.Line2D( (0, 1), (0, 0), @@ -1381,7 +1381,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) plt, has_line * sp[:legend_font_pointsize] / 8, ), - linestyle = _py_linestyle(:path, get_linestyle(series)), + linestyle = _py_linestyle(:path, get_line_style(series)), solid_capstyle = "butt", solid_joinstyle = "miter", dash_capstyle = "butt", diff --git a/src/types.jl b/src/types.jl index 7232fa172..b75e39e54 100644 --- a/src/types.jl +++ b/src/types.jl @@ -35,9 +35,9 @@ mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout parent, Series[], 0, - defaultminpad, - defaultbox, - defaultbox, + DEFAULT_MINPAD[], + DEFAULT_BBOX[], + DEFAULT_BBOX[], DefaultsDict(T, KW(), _subplot_defaults), nothing, nothing, diff --git a/src/utils.jl b/src/utils.jl index 5dd5430c2..504f98fd8 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -531,17 +531,17 @@ get_gradient(c) = cgrad() get_gradient(cg::ColorGradient) = cg get_gradient(cp::ColorPalette) = cgrad(cp, categorical = true) -get_linewidth(series, i::Int = 1) = _cycle(series[:line_width], i) -get_linestyle(series, i::Int = 1) = _cycle(series[:line_style], i) +get_line_width(series, i::Int = 1) = _cycle(series[:line_width], i) +get_line_style(series, i::Int = 1) = _cycle(series[:line_style], i) get_fillstyle(series, i::Int = 1) = _cycle(series[:fillstyle], i) -function get_markerstrokecolor(series, i::Int = 1) +function get_marker_stroke_color(series, i::Int = 1) msc = series[:marker_stroke_color] isa(msc, ColorGradient) ? msc : _cycle(msc, i) end -get_markerstrokealpha(series, i::Int = 1) = _cycle(series[:marker_stroke_alpha], i) -get_markerstrokewidth(series, i::Int = 1) = _cycle(series[:marker_stroke_width], i) +get_marke_rstroke_alpha(series, i::Int = 1) = _cycle(series[:marker_stroke_alpha], i) +get_marker_stroke_width(series, i::Int = 1) = _cycle(series[:marker_stroke_width], i) const _segmenting_vector_attributes = ( :seriescolor, From 6dfba96c4ea9335a2f4af4f9f5ab9cd8a89bd345 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Thu, 9 Mar 2023 16:56:54 +0100 Subject: [PATCH 22/27] harmonize funciton --- src/args.jl | 4 ++-- src/backends/deprecated/pgfplots.jl | 4 ++-- src/backends/deprecated/pyplot.jl | 12 +++++----- src/backends/gr.jl | 6 ++--- src/backends/hdf5.jl | 2 +- src/backends/inspectdr.jl | 2 +- src/backends/pgfplotsx.jl | 4 ++-- src/backends/plotly.jl | 12 +++++----- src/backends/pythonplot.jl | 34 ++++++++++++++--------------- src/backends/unicodeplots.jl | 7 ++++-- src/recipes.jl | 1 + src/utils.jl | 2 +- test/test_args.jl | 11 ++++++---- test/test_recipes.jl | 8 +------ 14 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/args.jl b/src/args.jl index 14987b1d8..3a8aa81c0 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1059,7 +1059,7 @@ end function processMarkerArg(plotattributes::AKW, arg) # markershape - if allShapes(arg) && !haskey(plotattributes, :markershape) + if allShapes(arg) && !haskey(plotattributes, :marker_shape) plotattributes[:marker_shape] = arg # stroke style @@ -2016,7 +2016,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) for s in (:line_, :marker_, :fill) csym, asym = Symbol(s, :color), Symbol(s, :alpha) plotattributes[csym] = if plotattributes[csym] === :auto - plot_color(if has_black_border_for_default(stype) && s === :line + plot_color(if has_black_border_for_default(stype) && s === :line_ sp[:foreground_color_subplot] else scolor diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index f9043b1bc..f52366923 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -125,8 +125,8 @@ function pgf_marker(plotattributes, i = 1) ) cstr_stroke, a_stroke = pgf_color( plot_color( - get_markerstrokecolor(plotattributes, i), - get_markerstrokealpha(plotattributes, i), + get_marker_stroke_color(plotattributes, i), + get_marker_stroke_alpha(plotattributes, i), ), ) return string( diff --git a/src/backends/deprecated/pyplot.jl b/src/backends/deprecated/pyplot.jl index 4819a43dd..4d9f0f7ba 100644 --- a/src/backends/deprecated/pyplot.jl +++ b/src/backends/deprecated/pyplot.jl @@ -495,10 +495,10 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) get_marker_alpha(series, i), ), edgecolors = py_color( - get_markerstrokecolor(series, i), - get_markerstrokealpha(series, i), + get_marker_stroke_color(series, i), + get_marker_stroke_alpha(series, i), ), - linewidths = py_thickness_scale(plt, get_markerstrokewidth(series, i)), + linewidths = py_thickness_scale(plt, get_marker_strokewidth(series, i)), extrakw..., ) push!(handles, handle) @@ -1504,8 +1504,8 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) marker = py_marker(_cycle(series[:marker_shape], 1)), markersize = py_thickness_scale(plt, 0.8sp[:legend_font_pointsize]), markeredgecolor = py_color( - single_color(get_markerstrokecolor(series)), - get_markerstrokealpha(series), + single_color(get_marker_stroke_color(series)), + get_marker_stroke_alpha(series), ), markerfacecolor = py_color( single_color(get_marker_color(series, clims)), @@ -1513,7 +1513,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) ), markeredgewidth = py_thickness_scale( plt, - 0.8get_markerstrokewidth(series) * sp[:legend_font_pointsize] / + 0.8get_marker_strokewidth(series) * sp[:legend_font_pointsize] / first(series[:marker_size]), ), # retain the markersize/markerstroke ratio from the markers on the plot ) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 427aaa07c..b85c37480 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -377,9 +377,9 @@ function gr_draw_marker(series, xi, yi, zi, clims, i, msize, strokewidth, shape: GR.fillarea(xs, ys) # draw the shapes - msc = get_markerstrokecolor(series, i) + msc = get_marker_stroke_color(series, i) gr_set_line(strokewidth, :solid, msc, series) - gr_set_transparency(msc, get_markerstrokealpha(series, i)) + gr_set_transparency(msc, get_marker_stroke_alpha(series, i)) GR.polyline(xs, ys) nothing end @@ -387,7 +387,7 @@ end # draw ONE symbol marker function gr_draw_marker(series, xi, yi, zi, clims, i, msize, strokewidth, shape::Symbol) GR.setborderwidth(strokewidth) - gr_set_bordercolor(get_markerstrokecolor(series, i)) + gr_set_bordercolor(get_marker_stroke_color(series, i)) gr_set_markercolor(get_marker_color(series, clims, i)) gr_set_transparency(get_marker_alpha(series, i)) GR.setmarkertype(gr_markertypes[shape]) diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index f2e220ec5..2091ce071 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -426,7 +426,7 @@ end # 1st arg appears to be ref to subplots. Seems to work without it. _read(::Type{Axis}, grp::Group) = - Axis([], DefaultsDict(Plots.Plot, _read(KW, grp["plotattributes"]), _axis_defaults)) + Axis([], DefaultsDict(Plot, _read(KW, grp["plotattributes"]), _axis_defaults)) # Not for use in main "Plot.subplots[]" hierarchy. Just establishes reference with subplot_index. _read(::Type{Subplot}, grp::Group) = diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index d0266f3d8..6d0f2110e 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -308,7 +308,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) shape = _inspectdr_mapglyph(series[:marker_shape]), size = _inspectdr_mapglyphsize(series[:marker_size]), color = _inspectdr_mapcolor( - plot_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), + plot_color(get_marker_stroke_color(series), get_marker_stroke_alpha(series)), ), fillcolor = _inspectdr_mapcolor( plot_color(get_marker_color(series, clims), get_marker_alpha(series)), diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 0dc8288f6..1e9111dcf 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -928,8 +928,8 @@ function pgfx_marker(plotattributes, i = 1) cstr = plot_color(get_marker_color(plotattributes, i), get_marker_alpha(plotattributes, i)) cstr_stroke = plot_color( - get_markerstrokecolor(plotattributes, i), - get_markerstrokealpha(plotattributes, i), + get_marker_stroke_color(plotattributes, i), + get_marker_stroke_alpha(plotattributes, i), ) mark_size = pgfx_thickness_scaling(plotattributes) * diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index c760b90bb..a715b12a6 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -700,8 +700,8 @@ function plotly_series(plt::Plot, series::Series) :color => rgba_string.( plot_color.( - get_markerstrokecolor.(series, inds), - get_markerstrokealpha.(series, inds), + get_marker_stroke_color.(series, inds), + get_marker_stroke_alpha.(series, inds), ), ), :width => _cycle(series[:marker_stroke_width], inds), @@ -865,14 +865,14 @@ function plotly_series_segments(series::Series, plotattributes_base::KW, x, y, z end lcolor = rgba_string( plot_color( - get_markerstrokecolor(series, i), - get_markerstrokealpha(series, i), + get_marker_stroke_color(series, i), + get_marker_stroke_alpha(series, i), ), ) lcolor_next = plot_color( - get_markerstrokecolor(series, i + 1), - get_markerstrokealpha(series, i + 1), + get_marker_stroke_color(series, i + 1), + get_marker_stroke_alpha(series, i + 1), ) |> rgba_string plotattributes_out[:marker] = KW( diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index c4c06a755..99efc172a 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -178,7 +178,7 @@ is_valid_cgrad_color(::Any) = false _py_linecolormap(series::Series) = if (color = get(series, :linecolor, nothing)) |> is_valid_cgrad_color - _py_colormap(cgrad(color, alpha = get_linealpha(series))) + _py_colormap(cgrad(color, alpha = get_line_alpha(series))) else nothing end @@ -368,7 +368,7 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) cbar_scale = sp[:colorbar_scale] linewidths = linewidth = _py_thickness_scale(plt, get_line_width(series)) linestyles = linestyle = _py_linestyle(st, get_line_style(series)) - edgecolor = edgecolors = _py_color(get_linecolor(series, 1, cbar_scale)) + edgecolor = edgecolors = _py_color(get_line_color(series, 1, cbar_scale)) facecolor = facecolors = _py_color(series[:fillcolor]) zorder = series[:series_plotindex] alpha = get_fillalpha(series) @@ -382,8 +382,8 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) map(arg -> arg[rng], xyargs)...; label = k == 1 ? label : "", color = _py_color( - single_color(get_linecolor(series, clims, i, cbar_scale)), - get_linealpha(series, i), + single_color(get_line_color(series, clims, i, cbar_scale)), + get_line_alpha(series, i), ), linewidth = _py_thickness_scale(plt, get_line_width(series, i)), linestyle = _py_linestyle(st, get_line_style(series, i)), @@ -440,10 +440,10 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) get_markeralpha(series, i), ), edgecolors = _py_color( - get_markerstrokecolor(series, i), - get_markerstrokealpha(series, i), + get_marker_stroke_color(series, i), + get_marker_stroke_alpha(series, i), ), - linewidths = _py_thickness_scale(plt, get_markerstrokewidth(series, i)), + linewidths = _py_thickness_scale(plt, get_marker_strokewidth(series, i)), label, extrakw..., ) |> push_h @@ -454,9 +454,9 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) for segment in series_segments(series) i, rng = segment.attr_index, segment.range if length(rng) > 1 - lc = get_linecolor(series, clims, i, cbar_scale) + lc = get_line_color(series, clims, i, cbar_scale) fc = get_fillcolor(series, clims, i) - la = get_linealpha(series, i) + la = get_line_alpha(series, i) fa = get_fillalpha(series, i) ls = get_line_style(series, i) fs = get_fillstyle(series, i) @@ -717,7 +717,7 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) dim1, _cycle(fillrange[1], rng), _cycle(fillrange[2], rng) end - la = get_linealpha(series, i) + la = get_line_alpha(series, i) fc = get_fillcolor(series, clims, i) fa = get_fillalpha(series, i) fs = get_fillstyle(series, i) @@ -1337,9 +1337,9 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) nseries += 1 # add a line/marker and a label if series[:seriestype] === :shape || series[:fillrange] !== nothing - lc = get_linecolor(series, clims) + lc = get_line_color(series, clims) fc = get_fillcolor(series, clims) - la = get_linealpha(series) + la = get_line_alpha(series) fa = get_fillalpha(series) ls = get_line_style(series) fs = get_fillstyle(series) @@ -1374,8 +1374,8 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) (0, 1), (0, 0), color = _py_color( - single_color(get_linecolor(series, clims)), - get_linealpha(series), + single_color(get_line_color(series, clims)), + get_line_alpha(series), ), linewidth = _py_thickness_scale( plt, @@ -1389,8 +1389,8 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) marker = _py_marker(_cycle(series[:markershape], 1)), markersize = _py_thickness_scale(plt, 0.8sp[:legend_font_pointsize]), markeredgecolor = _py_color( - single_color(get_markerstrokecolor(series)), - get_markerstrokealpha(series), + single_color(get_marker_stroke_color(series)), + get_marker_stroke_alpha(series), ), markerfacecolor = _py_color( single_color(get_markercolor(series, clims, 1, sp[:colorbar_scale])), @@ -1398,7 +1398,7 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) ), markeredgewidth = _py_thickness_scale( plt, - 0.8get_markerstrokewidth(series) * sp[:legend_font_pointsize] / + 0.8get_marker_strokewidth(series) * sp[:legend_font_pointsize] / first(series[:markersize]), ), # retain the markersize/markerstroke ratio from the markers on the plot ) |> push_h diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 70a22dbca..4d38246a5 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -207,7 +207,7 @@ function addUnicodeSeries!( kw = ( kw..., zlabel = sp[:colorbar_title], - color = st ≡ :wireframe ? up_color(get_linecolor(series, 1)) : nothing, + color = st ≡ :wireframe ? up_color(get_line_color(series, 1)) : nothing, colormap = colormap ≡ :none ? up_cmap(series) : colormap, colorbar = hascolorbar(sp), zscale, @@ -291,7 +291,10 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{UnicodePlotsBackend}) if (l = plt.layout[r, c]) isa GridLayout && size(l) != (1, 1) unsupported_layout_error() else - img = UnicodePlots.png_image(plt.o[sps += 1]; pixelsize = 32) + img = UnicodePlots.png_image(plt.o[sps += 1]; + pixelsize = 32, + font = plt[:fontfamily], + ) img ≡ nothing && continue canvas_type = eltype(img) s1[r, c], s2[r, c] = size(img) diff --git a/src/recipes.jl b/src/recipes.jl index 2af3ecbbb..af8556770 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -465,6 +465,7 @@ end # draw the bar shapes @series begin + # line_color --> :black seriestype := :shape series_annotations := nothing primary := true diff --git a/src/utils.jl b/src/utils.jl index 504f98fd8..b391593ac 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -540,7 +540,7 @@ function get_marker_stroke_color(series, i::Int = 1) isa(msc, ColorGradient) ? msc : _cycle(msc, i) end -get_marke_rstroke_alpha(series, i::Int = 1) = _cycle(series[:marker_stroke_alpha], i) +get_marker_stroke_alpha(series, i::Int = 1) = _cycle(series[:marker_stroke_alpha], i) get_marker_stroke_width(series, i::Int = 1) = _cycle(series[:marker_stroke_width], i) const _segmenting_vector_attributes = ( diff --git a/test/test_args.jl b/test/test_args.jl index f02b1f444..2fe91a1b4 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -1,3 +1,4 @@ +using Plots, Test struct Foo{T} x::Vector{T} y::Vector{T} @@ -15,14 +16,14 @@ x = collect(0.0:10.0) foo = Foo(x, sin.(x)) @testset "Magic attributes" begin - @test plot(foo)[1][1][:markershape] === :+ - @test plot(foo, markershape = :diamond)[1][1][:markershape] === :diamond - @test plot(foo, marker = :diamond)[1][1][:markershape] === :diamond + @test plot(foo)[1][1][:marker_shape] === :+ + @test plot(foo, markershape = :diamond)[1][1][:marker_shape] === :diamond + @test plot(foo, marker = :diamond)[1][1][:marker_shape] === :diamond @test (@test_logs (:warn, "Skipped marker arg diamond.") plot( foo, marker = :diamond, markershape = :diamond, - )[1][1][:markershape]) === :diamond + )[1][1][:marker_shape]) === :diamond end using Plots, Test @@ -62,6 +63,8 @@ end @test filter(isfinite, pl1[1][1][:x]) == filter(isfinite, pl2[1][1][:y]) @test filter(isfinite, pl1[1][1][:y]) == filter(isfinite, pl2[1][1][:x]) @test pl1[1][1][:line_color] == RGBA{Float64}(0.0,0.0,0.0,1.0) + @test pl1[1][2][:marker_size] == 0 + @test pl1[1][2][:marker_alpha] == 0 end @testset "@add_attributes" begin diff --git a/test/test_recipes.jl b/test/test_recipes.jl index e8c9ecd95..00298bc2d 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -1,3 +1,4 @@ +using Plots, Test using OffsetArrays @testset "User recipes" begin @@ -139,10 +140,3 @@ with(:gr) do show(devnull, bar([1 2 3], [0.02 125 10_000]; yscale = :log10)) end end - -@testset "Bar" begin - pl = bar(["a", "b", "c"], [1,2,3]) - @test pl[1][2][:marker_size] == 0 - @test pl[1][2][:marker_alpha] == 0 - @test pl[1][1][:line_color] == RGBA{Float64}(0.0,0.0,0.0,1.0) -end From f737e0f5efc77e5e70f7a55af43b30d1a4348e50 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 10 Mar 2023 13:29:58 +0100 Subject: [PATCH 23/27] fix tests --- src/backends/deprecated/pyplot.jl | 4 ++-- src/backends/pythonplot.jl | 14 +++++++------- test/test_animations.jl | 2 +- test/test_preferences.jl | 2 ++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/backends/deprecated/pyplot.jl b/src/backends/deprecated/pyplot.jl index 4d9f0f7ba..e925599d8 100644 --- a/src/backends/deprecated/pyplot.jl +++ b/src/backends/deprecated/pyplot.jl @@ -498,7 +498,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) get_marker_stroke_color(series, i), get_marker_stroke_alpha(series, i), ), - linewidths = py_thickness_scale(plt, get_marker_strokewidth(series, i)), + linewidths = py_thickness_scale(plt, get_marker_stroke_width(series, i)), extrakw..., ) push!(handles, handle) @@ -1513,7 +1513,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) ), markeredgewidth = py_thickness_scale( plt, - 0.8get_marker_strokewidth(series) * sp[:legend_font_pointsize] / + 0.8get_marker_stroke_width(series) * sp[:legend_font_pointsize] / first(series[:marker_size]), ), # retain the markersize/markerstroke ratio from the markers on the plot ) diff --git a/src/backends/pythonplot.jl b/src/backends/pythonplot.jl index 99efc172a..f91752cbc 100644 --- a/src/backends/pythonplot.jl +++ b/src/backends/pythonplot.jl @@ -190,7 +190,7 @@ _py_fillcolormap(series::Series) = end _py_markercolormap(series::Series) = if (color = get(series, :markercolor, nothing)) |> is_valid_cgrad_color - _py_colormap(cgrad(color, alpha = get_markeralpha(series))) + _py_colormap(cgrad(color, alpha = get_marker_alpha(series))) else nothing end @@ -436,14 +436,14 @@ function _py_add_series(plt::Plot{PythonPlotBackend}, series::Series) marker = _py_marker(_cycle(series[:markershape], i)), s = _py_thickness_scale(plt, _cycle(series[:markersize], i)) .^ 2, facecolors = _py_color( - get_markercolor(series, i, cbar_scale), - get_markeralpha(series, i), + get_marker_color(series, i, cbar_scale), + get_marker_alpha(series, i), ), edgecolors = _py_color( get_marker_stroke_color(series, i), get_marker_stroke_alpha(series, i), ), - linewidths = _py_thickness_scale(plt, get_marker_strokewidth(series, i)), + linewidths = _py_thickness_scale(plt, get_marker_stroke_width(series, i)), label, extrakw..., ) |> push_h @@ -1393,12 +1393,12 @@ function _py_add_legend(plt::Plot, sp::Subplot, ax) get_marker_stroke_alpha(series), ), markerfacecolor = _py_color( - single_color(get_markercolor(series, clims, 1, sp[:colorbar_scale])), - get_markeralpha(series), + single_color(get_marker_color(series, clims, 1, sp[:colorbar_scale])), + get_marker_alpha(series), ), markeredgewidth = _py_thickness_scale( plt, - 0.8get_marker_strokewidth(series) * sp[:legend_font_pointsize] / + 0.8get_marker_stroke_width(series) * sp[:legend_font_pointsize] / first(series[:markersize]), ), # retain the markersize/markerstroke ratio from the markers on the plot ) |> push_h diff --git a/test/test_animations.jl b/test/test_animations.jl index 4ad7fe2e6..d94d9068e 100644 --- a/test/test_animations.jl +++ b/test/test_animations.jl @@ -43,7 +43,7 @@ end circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines) end when i % 5 == 0 fps = 10 - @test_throws LoadError macroexpand( + @test_throws ErrorException macroexpand( @__MODULE__, quote @gif for i in 1:n diff --git a/test/test_preferences.jl b/test/test_preferences.jl index 033087001..e09d25860 100644 --- a/test/test_preferences.jl +++ b/test/test_preferences.jl @@ -35,6 +35,8 @@ using Pkg, Test; io = (devnull, stdout)[1] # toggle for debugging Pkg.activate(; temp = true, io) Pkg.develop(; path = "$(escape_string(pkgdir(Plots)))", io) + Pkg.develop(; path = "$(escape_string(joinpath(pkgdir(Plots), "RecipesPipeline")))", io) + Pkg.develop(; path = "$(escape_string(joinpath(pkgdir(Plots), "RecipesBase")))", io) Pkg.add("UnicodePlots"; io) # checked by Plots using Plots res = @testset "Prefs" begin From 0150ad25ee37c8346b71bd890c188286134beaed Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 10 Mar 2023 15:42:10 +0100 Subject: [PATCH 24/27] fix recipespipeline tests --- RecipesPipeline/src/utils.jl | 13 ++++++++++--- RecipesPipeline/test/runtests.jl | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/RecipesPipeline/src/utils.jl b/RecipesPipeline/src/utils.jl index 65df728e3..89a5e4ff4 100644 --- a/RecipesPipeline/src/utils.jl +++ b/RecipesPipeline/src/utils.jl @@ -13,8 +13,11 @@ struct DefaultsDict{P} <: AbstractDict{Symbol,Any} plot_type::Type{P} explicit::KW defaults::KW - function DefaultsDict{P}(plot_type::Type{P}, explicit::KW, defaults::KW) where P - e = KW( key_alias(plot_type, k) => v === :seriestype ? type_alias(plot_type, v) : v for (k, v) in explicit) + function DefaultsDict{P}(plot_type::Type{P}, explicit::AbstractDict, defaults::AbstractDict) where {P} + e = KW( + key_alias(plot_type, k) => v === :seriestype ? type_alias(plot_type, v) : v + for (k, v) in explicit + ) new{P}(plot_type, e, defaults) end end @@ -22,7 +25,11 @@ end DefaultsDict(pt, e, d) = DefaultsDict{pt}(pt, e, d) function Base.merge(d1::DefaultsDict, d2::DefaultsDict) @assert d1.plot_type === d2.plot_type - DefaultsDict(d1.plot_type, merge(d1.explicit, d2.explicit), merge(d1.defaults, d2.defaults)) + DefaultsDict( + d1.plot_type, + merge(d1.explicit, d2.explicit), + merge(d1.defaults, d2.defaults), + ) end function Base.getindex(dd::DefaultsDict, k) k = key_alias(dd.plot_type, k) diff --git a/RecipesPipeline/test/runtests.jl b/RecipesPipeline/test/runtests.jl index a05b112a4..88111c3bd 100644 --- a/RecipesPipeline/test/runtests.jl +++ b/RecipesPipeline/test/runtests.jl @@ -6,8 +6,10 @@ using Test import RecipesPipeline: _prepare_series_data import RecipesBase +struct MyPlot end + @testset "DefaultsDict" begin - dd = DefaultsDict(Plots.Plot, Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) + dd = DefaultsDict(MyPlot, Dict(:foo => 1, :bar => missing), Dict(:foo => nothing, :baz => 'x')) @test all(explicitkeys(dd) .== [:bar, :foo]) @test all(defaultkeys(dd) .== [:baz, :foo]) From c49da2868eb49aa3bc5436ba65b6b32516f9fa42 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 10 Mar 2023 18:03:14 +0100 Subject: [PATCH 25/27] adlust benchmarks, revert macro test --- .github/workflows/benchmark.yml | 9 ++++++--- test/test_animations.jl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e46a09f92..54bfc8a63 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -3,7 +3,7 @@ name: benchmarks on: pull_request: -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true @@ -14,11 +14,14 @@ jobs: steps: - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@latest - + - name: Ubuntu TESTCMD run: echo "TESTCMD=xvfb-run --auto-servernum julia" >> $GITHUB_ENV - name: Install Plots dependencies - uses: julia-actions/julia-buildpkg@latest + shell: xvfb-run julia --project=@. --color=yes {0} + run: | + using Pkg + foreach(path -> Pkg.develop(; path), ("RecipesBase", "RecipesPipeline", ".")) - name: Install Benchmarking dependencies run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI"' diff --git a/test/test_animations.jl b/test/test_animations.jl index d94d9068e..4ad7fe2e6 100644 --- a/test/test_animations.jl +++ b/test/test_animations.jl @@ -43,7 +43,7 @@ end circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines) end when i % 5 == 0 fps = 10 - @test_throws ErrorException macroexpand( + @test_throws LoadError macroexpand( @__MODULE__, quote @gif for i in 1:n From 33bae7f340b81176bc2f79fb0024956355de9e21 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 10 Mar 2023 18:05:50 +0100 Subject: [PATCH 26/27] don't dev Plots twice --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 54bfc8a63..3341cc75c 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -21,7 +21,7 @@ jobs: shell: xvfb-run julia --project=@. --color=yes {0} run: | using Pkg - foreach(path -> Pkg.develop(; path), ("RecipesBase", "RecipesPipeline", ".")) + foreach(path -> Pkg.develop(; path), ("RecipesBase", "RecipesPipeline")) - name: Install Benchmarking dependencies run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI"' From 7705f8a418de166c087c80c19a1ca8a01215c931 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 10 Mar 2023 16:34:03 +0100 Subject: [PATCH 27/27] format --- src/arg_desc.jl | 92 ++++++++++++++--------------- src/args.jl | 48 ++++++++++----- src/backends/deprecated/pgfplots.jl | 5 +- src/backends/gr.jl | 7 ++- src/backends/inspectdr.jl | 5 +- src/backends/unicodeplots.jl | 3 +- src/components.jl | 10 ++-- src/consts.jl | 3 +- test/test_args.jl | 5 +- test/test_recipes.jl | 6 +- 10 files changed, 108 insertions(+), 76 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index daa27a6d9..406f6bf8c 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -5,60 +5,60 @@ const TicksType = Union{AVec{Real},Tuple{AVec{Real},AVec{AStr}},Symbol,Bool,Noth # NOTE: when updating `arg_desc`, don't forget to modify `PlotDocs.make_attr_df` accordingly. const _arg_desc = KW( # series args - :label => (AStr, "The label for a series, which appears in a legend. If empty, no legend entry is added."), - :seriescolor => (ColorType, "The base color for this series. `:auto` (the default) will select a color from the subplot's `color_palette`, based on the order it was added to the subplot. Also describes the colormap for surfaces."), - :seriesalpha => (Real, "The alpha/opacity override for the series. `nothing` (the default) means it will take the alpha value of the color."), - :seriestype => (Symbol, "This is the identifier of the type of visualization for this series. Choose from $(_allTypes) or any series recipes which are defined."), + :label => (AStr, "The label for a series, which appears in a legend. If empty, no legend entry is added."), + :seriescolor => (ColorType, "The base color for this series. `:auto` (the default) will select a color from the subplot's `color_palette`, based on the order it was added to the subplot. Also describes the colormap for surfaces."), + :seriesalpha => (Real, "The alpha/opacity override for the series. `nothing` (the default) means it will take the alpha value of the color."), + :seriestype => (Symbol, "This is the identifier of the type of visualization for this series. Choose from $(_allTypes) or any series recipes which are defined."), :line_style => (Symbol, "Style of the line (for path and bar stroke). Choose from $(_allStyles)"), :line_width => (Real, "Width of the line (in pixels)."), :line_color => (ColorType, "Color of the line (for path and bar stroke). `:match` will take the value from `:seriescolor`, (though histogram/bar types use `:black` as a default)."), :line_alpha => (Real, "The alpha/opacity override for the line. `nothing` (the default) means it will take the alpha value of linecolor."), - :fillrange => (Union{Real,AVec}, "Fills area between fillrange and `y` for line-types, sets the base for `bar`, `sticks` types, and similar for other types."), - :fillcolor => (ColorType, "Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`."), - :fillalpha => (Real, "The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor."), + :fillrange => (Union{Real,AVec}, "Fills area between fillrange and `y` for line-types, sets the base for `bar`, `sticks` types, and similar for other types."), + :fillcolor => (ColorType, "Color of the filled area of path or bar types. `:match` will take the value from `:seriescolor`."), + :fillalpha => (Real, "The alpha/opacity override for the fill area. `nothing` (the default) means it will take the alpha value of fillcolor."), :marker_shape => (Union{Symbol,Shape,AVec}, "Choose from $(_allMarkers)."), - :fillstyle => (Symbol, "Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x."), + :fillstyle => (Symbol, "Style of the fill area. `nothing` (the default) means solid fill. Choose from :/, :\\, :|, :-, :+, :x."), :marker_color => (ColorType, "Color of the interior of the marker or shape. `:match` will take the value from `:seriescolor`."), :marker_alpha => (Real, "The alpha/opacity override for the marker interior. `nothing` (the default) means it will take the alpha value of markercolor."), :marker_size => (Union{Real,AVec}, "Size (radius pixels) of the markers."), - :marker_stroke_style => (Symbol, "Style of the marker stroke (border). Choose from $(_allStyles)."), - :marker_stroke_width => (Real, "Width of the marker stroke (border) in pixels."), - :marker_stroke_color => (ColorType, "Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`."), - :marker_stroke_alpha => (Real, "The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor."), - :bins => (Union{Integer,NTuple{2,Integer},AVec,Symbol}, """ - Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). - For fine-grained control pass a Vector of break values, e.g. `range(minimum(x), stop = maximum(x), length = 25)`."""), - :smooth => (Bool, "Add a regression line ?"), - :group => (AVec, "Data is split into a separate series, one for each unique value in `group`."), - :x => (Any, "Input data (first dimension)."), - :y => (Any, "Input data (second dimension)."), - :z => (Any, "Input data (third dimension). May be wrapped by a `Surface` for surface and heatmap types."), - :marker_z => (Union{AVec,Function}, "z-values for each series data point, which correspond to the color to be used from a markercolor gradient (`f(x,y,z) -> z_value` or `f(x,y) -> z_value`)."), - :line_z => (Union{AVec,Function}, "z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment)."), - :fill_z => (AMat, "Matrix of the same size as z matrix, which specifies the color of the 3D surface."), - :levels => (Union{AVec,Integer}, "Singleton for number of contours or iterable for contour values. Determines contour levels for a contour type."), - :permute => (NTuple{2,Symbol}, "Permutes data and axis properties of the axes given in the tuple, e.g. (:x, :y)."), - :orientation => (Symbol, "(deprecated) Horizontal or vertical orientation for bar types. Values `:h`, `:hor`, `:horizontal` correspond to horizontal (sideways, anchored to y-axis), and `:v`, `:vert`, and `:vertical` correspond to vertical (the default)."), - :bar_position => (Symbol, "Choose from `:overlay` (default), `:stack`. (warning: may only be partially implemented)."), - :bar_width => (Real, " Width of bars in data coordinates. When `nothing`, chooses based on `x` (or `y` when `orientation = :h`)."), - :bar_edges => (Bool, "Align bars to edges (true), or centers (the default) ?"), - :xerror => (Union{AVec,NTuple{2,AVec}}, "`x` (horizontal) error relative to x-value. If 2-tuple of vectors, the first vector corresponds to the left error (and the second to the right)."), - :yerror => (Union{AVec,NTuple{2,AVec}}, "`y` (vertical) error relative to y-value. If 2-tuple of vectors, the first vector corresponds to the bottom error (and the second to the top)."), - :ribbon => (Union{Real,AVec}, "Creates a fillrange around the data points."), - :quiver => (Union{AVec,NTuple{2,AVec}}, "The directional vectors U,V which specify velocity/gradient vectors for a quiver plot."), - :arrow => (Union{Bool,Arrow}, "Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar."), - :normalize => (Union{Bool,Symbol}, "Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a discrete PDF, where the total area of the bins is 1), :probability (bin heights sum to 1) and :density (the area of each bin, rather than the height, is equal to the counts - useful for uneven bin sizes)."), - :weights => (AVec, "Used in histogram types for weighted counts."), - :show_empty_bins => (Bool, "Whether empty bins in a 2D histogram are colored as 0 (true), or transparent (the default)."), - :contours => (Bool, "Add contours to the side-grids of 3D plots? Used in surface/wireframe."), - :contour_labels => (Bool, "Show labels at the contour lines ?"), - :match_dimensions => (Bool, "For heatmap types: should the first dimension of a matrix (rows) correspond to the first dimension of the plot (`x`-axis) ? Defaults to `false`, which matches the behavior of Matplotlib, Plotly, and others. Note: when passing a function for `z`, the function should still map `(x,y) -> z`."), - :subplot => (Union{Integer,Subplot}, "The subplot that this series belongs to."), - :series_annotations => (Union{AVec,AStr,PlotText}, "These are annotations which are mapped to data points/positions."), - :primary => (Bool, "Does this count as a 'real series'? For example, you could have a path (primary), and a scatter (secondary) as two separate series, maybe with different data (see `sticks` recipe for an example). The secondary series will get the same color, etc as the primary."), - :hover => (AVec{AStr}, "Text to display when hovering over each data point."), - :colorbar_entry => (Bool, "Include this series in the color bar? Set to `false` to exclude."), - :z_order => (Union{Symbol,Integer}, ":front (default), :back or index of position where 1 is furthest in the background."), + :marker_stroke_style => (Symbol, "Style of the marker stroke (border). Choose from $(_allStyles)."), + :marker_stroke_width => (Real, "Width of the marker stroke (border) in pixels."), + :marker_stroke_color => (ColorType, "Color of the marker stroke (border). `:match` will take the value from `:foreground_color_subplot`."), + :marker_stroke_alpha => (Real, "The alpha/opacity override for the marker stroke (border). `nothing` (the default) means it will take the alpha value of markerstrokecolor."), + :bins => (Union{Integer,NTuple{2,Integer},AVec,Symbol}, """ + Default is :auto (the Freedman-Diaconis rule). For histogram-types, defines the approximate number of bins to aim for, or the auto-binning algorithm to use (:sturges, :sqrt, :rice, :scott or :fd). + For fine-grained control pass a Vector of break values, e.g. `range(minimum(x), stop = maximum(x), length = 25)`."""), + :smooth => (Bool, "Add a regression line ?"), + :group => (AVec, "Data is split into a separate series, one for each unique value in `group`."), + :x => (Any, "Input data (first dimension)."), + :y => (Any, "Input data (second dimension)."), + :z => (Any, "Input data (third dimension). May be wrapped by a `Surface` for surface and heatmap types."), + :marker_z => (Union{AVec,Function}, "z-values for each series data point, which correspond to the color to be used from a markercolor gradient (`f(x,y,z) -> z_value` or `f(x,y) -> z_value`)."), + :line_z => (Union{AVec,Function}, "z-values for each series line segment, which correspond to the color to be used from a linecolor gradient. Note that for N points, only the first N-1 values are used (one per line-segment)."), + :fill_z => (AMat, "Matrix of the same size as z matrix, which specifies the color of the 3D surface."), + :levels => (Union{AVec,Integer}, "Singleton for number of contours or iterable for contour values. Determines contour levels for a contour type."), + :permute => (NTuple{2,Symbol}, "Permutes data and axis properties of the axes given in the tuple, e.g. (:x, :y)."), + :orientation => (Symbol, "(deprecated) Horizontal or vertical orientation for bar types. Values `:h`, `:hor`, `:horizontal` correspond to horizontal (sideways, anchored to y-axis), and `:v`, `:vert`, and `:vertical` correspond to vertical (the default)."), + :bar_position => (Symbol, "Choose from `:overlay` (default), `:stack`. (warning: may only be partially implemented)."), + :bar_width => (Real, " Width of bars in data coordinates. When `nothing`, chooses based on `x` (or `y` when `orientation = :h`)."), + :bar_edges => (Bool, "Align bars to edges (true), or centers (the default) ?"), + :xerror => (Union{AVec,NTuple{2,AVec}}, "`x` (horizontal) error relative to x-value. If 2-tuple of vectors, the first vector corresponds to the left error (and the second to the right)."), + :yerror => (Union{AVec,NTuple{2,AVec}}, "`y` (vertical) error relative to y-value. If 2-tuple of vectors, the first vector corresponds to the bottom error (and the second to the top)."), + :ribbon => (Union{Real,AVec}, "Creates a fillrange around the data points."), + :quiver => (Union{AVec,NTuple{2,AVec}}, "The directional vectors U,V which specify velocity/gradient vectors for a quiver plot."), + :arrow => (Union{Bool,Arrow}, "Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar."), + :normalize => (Union{Bool,Symbol}, "Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a discrete PDF, where the total area of the bins is 1), :probability (bin heights sum to 1) and :density (the area of each bin, rather than the height, is equal to the counts - useful for uneven bin sizes)."), + :weights => (AVec, "Used in histogram types for weighted counts."), + :show_empty_bins => (Bool, "Whether empty bins in a 2D histogram are colored as 0 (true), or transparent (the default)."), + :contours => (Bool, "Add contours to the side-grids of 3D plots? Used in surface/wireframe."), + :contour_labels => (Bool, "Show labels at the contour lines ?"), + :match_dimensions => (Bool, "For heatmap types: should the first dimension of a matrix (rows) correspond to the first dimension of the plot (`x`-axis) ? Defaults to `false`, which matches the behavior of Matplotlib, Plotly, and others. Note: when passing a function for `z`, the function should still map `(x,y) -> z`."), + :subplot => (Union{Integer,Subplot}, "The subplot that this series belongs to."), + :series_annotations => (Union{AVec,AStr,PlotText}, "These are annotations which are mapped to data points/positions."), + :primary => (Bool, "Does this count as a 'real series'? For example, you could have a path (primary), and a scatter (secondary) as two separate series, maybe with different data (see `sticks` recipe for an example). The secondary series will get the same color, etc as the primary."), + :hover => (AVec{AStr}, "Text to display when hovering over each data point."), + :colorbar_entry => (Bool, "Include this series in the color bar? Set to `false` to exclude."), + :z_order => (Union{Symbol,Integer}, ":front (default), :back or index of position where 1 is furthest in the background."), # plot args :plot_title => (AStr, "Whole plot title (not to be confused with the title for individual subplots)."), diff --git a/src/args.jl b/src/args.jl index 3a8aa81c0..65af59b05 100644 --- a/src/args.jl +++ b/src/args.jl @@ -6,7 +6,15 @@ function make_non_underscore(s::Symbol) end const _keyAliases = Dict{Symbol,Symbol}() -const _generalAliases = ("background" => "bg", "foreground" => "fg", "pointsize" => "size", "yfill" => "fill", "alpha" => "a", "alpha" => "opacity", "alpha" => "α") +const _generalAliases = ( + "background" => "bg", + "foreground" => "fg", + "pointsize" => "size", + "yfill" => "fill", + "alpha" => "a", + "alpha" => "opacity", + "alpha" => "α", +) function add_aliases(sym::Symbol, aliases::Symbol...) for alias in aliases @@ -2029,13 +2037,14 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) end # update markerstrokecolor - plotattributes[:marker_stroke_color] = if plotattributes[:marker_stroke_color] === :match - plot_color(sp[:foreground_color_subplot]) - elseif plotattributes[:marker_stroke_color] === :auto - get_series_color(plotattributes[:marker_color], sp, plotIndex, stype) - else - get_series_color(plotattributes[:marker_stroke_color], sp, plotIndex, stype) - end + plotattributes[:marker_stroke_color] = + if plotattributes[:marker_stroke_color] === :match + plot_color(sp[:foreground_color_subplot]) + elseif plotattributes[:marker_stroke_color] === :auto + get_series_color(plotattributes[:marker_color], sp, plotIndex, stype) + else + get_series_color(plotattributes[:marker_stroke_color], sp, plotIndex, stype) + end # if marker_z, fill_z or line_z are set, ensure we have a gradient if plotattributes[:marker_z] !== nothing @@ -2135,12 +2144,17 @@ macro add_attributes(level, expr, args...) )), ) if aliases !== nothing - pl_aliases = Plots.makeplural.(aliases) - push!( - insert_block.args, - :(Plots.add_aliases($(QuoteNode(exp_key)), $(aliases)..., $(pl_aliases)..., $(Iterators.flatten(Plots.make_non_underscore.(aliases)))..., $(Iterators.flatten(Plots.make_non_underscore.(pl_aliases)))..., - )) - ) + pl_aliases = Plots.makeplural.(aliases) + push!( + insert_block.args, + :(Plots.add_aliases( + $(QuoteNode(exp_key)), + $(aliases)..., + $(pl_aliases)..., + $(Iterators.flatten(Plots.make_non_underscore.(aliases)))..., + $(Iterators.flatten(Plots.make_non_underscore.(pl_aliases)))..., + )), + ) end end quote @@ -2177,7 +2191,11 @@ function _splitdef!(blk, key_dict) end defexpr = ei.args[2] # defexpr # filter e.g. marker::Marker = Marker(...) - if !(defexpr isa Expr && defexpr.head == :call && defexpr.args[1] == ei.args[1].args[2]) + if !( + defexpr isa Expr && + defexpr.head == :call && + defexpr.args[1] == ei.args[1].args[2] + ) key_dict[var] = defexpr end blk.args[i] = lhs diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index f52366923..2731b72fb 100644 --- a/src/backends/deprecated/pgfplots.jl +++ b/src/backends/deprecated/pgfplots.jl @@ -121,7 +121,10 @@ end function pgf_marker(plotattributes, i = 1) shape = _cycle(plotattributes[:marker_shape], i) cstr, a = pgf_color( - plot_color(get_marker_color(plotattributes, i), get_marker_alpha(plotattributes, i)), + plot_color( + get_marker_color(plotattributes, i), + get_marker_alpha(plotattributes, i), + ), ) cstr_stroke, a_stroke = pgf_color( plot_color( diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b85c37480..a9bb9a374 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1883,7 +1883,12 @@ end function gr_draw_contour(series, x, y, z, clims) GR.setprojectiontype(0) GR.setspace(clims[1], clims[2], 0, 90) - gr_set_line(get_line_width(series), get_line_style(series), get_line_color(series), series) + gr_set_line( + get_line_width(series), + get_line_style(series), + get_line_color(series), + series, + ) gr_set_transparency(get_fillalpha(series)) h = gr_contour_levels(series, clims) if series[:fillrange] !== nothing diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 6d0f2110e..8660ab6f9 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -308,7 +308,10 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) shape = _inspectdr_mapglyph(series[:marker_shape]), size = _inspectdr_mapglyphsize(series[:marker_size]), color = _inspectdr_mapcolor( - plot_color(get_marker_stroke_color(series), get_marker_stroke_alpha(series)), + plot_color( + get_marker_stroke_color(series), + get_marker_stroke_alpha(series), + ), ), fillcolor = _inspectdr_mapcolor( plot_color(get_marker_color(series, clims), get_marker_alpha(series)), diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 4d38246a5..02c77362c 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -291,7 +291,8 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{UnicodePlotsBackend}) if (l = plt.layout[r, c]) isa GridLayout && size(l) != (1, 1) unsupported_layout_error() else - img = UnicodePlots.png_image(plt.o[sps += 1]; + img = UnicodePlots.png_image( + plt.o[sps += 1]; pixelsize = 32, font = plt[:fontfamily], ) diff --git a/src/components.jl b/src/components.jl index c38b36ad0..daa4d797b 100644 --- a/src/components.jl +++ b/src/components.jl @@ -837,9 +837,11 @@ end :match = ( :legend_title_font_family, :legend_title_font_color, ) :aliases = Dict( - :legend_position => (:legend, :leg, :key), - :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), - :legend_foreground_color => (:foreground_legend, :foreground_color_legend, :foreground_colour_legend) + :legend_position => (:legend, :leg, :key), + :legend_background_color => + (:background_legend, :background_colour_legend, :background_color_legend), + :legend_foreground_color => + (:foreground_legend, :foreground_color_legend, :foreground_colour_legend), ) ### Line @@ -854,7 +856,6 @@ end :aliases = Dict( :line_alpha => (:lalpha,), :line_width => (:w, :width, :lw), :line_style => (:s, :style, :ls), - ) ### Marker @@ -874,4 +875,3 @@ end :aliases = Dict( :marker_stroke_alpha => (:msalpha,), :marker_stroke_width => (:msw, :mswidth), ) - diff --git a/src/consts.jl b/src/consts.jl index 38f547d2c..ee16414a2 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -69,7 +69,8 @@ const _all_plot_args = _plot_args const _all_args = union(_lettered_all_axis_args, _all_subplot_args, _all_series_args, _all_plot_args) -const _all_segmenting_attributes = Set(_segmenting_vector_attributes ∪ _segmenting_array_attributes) +const _all_segmenting_attributes = + Set(_segmenting_vector_attributes ∪ _segmenting_array_attributes) # add all pluralized forms to the _keyAliases dict for arg in _all_args diff --git a/test/test_args.jl b/test/test_args.jl index 2fe91a1b4..157320613 100644 --- a/test/test_args.jl +++ b/test/test_args.jl @@ -62,7 +62,7 @@ end @test yticks(pl2) == xticks(pl1) @test filter(isfinite, pl1[1][1][:x]) == filter(isfinite, pl2[1][1][:y]) @test filter(isfinite, pl1[1][1][:y]) == filter(isfinite, pl2[1][1][:x]) - @test pl1[1][1][:line_color] == RGBA{Float64}(0.0,0.0,0.0,1.0) + @test pl1[1][1][:line_color] == RGBA{Float64}(0.0, 0.0, 0.0, 1.0) @test pl1[1][2][:marker_size] == 0 @test pl1[1][2][:marker_alpha] == 0 end @@ -84,7 +84,8 @@ end :legend_title_font_color, ) :aliases = Dict( :legend_position => (:legend, :leg, :key), - :legend_background_color => (:background_legend, :background_colour_legend, :background_color_legend), + :legend_background_color => + (:background_legend, :background_colour_legend, :background_color_legend), :legend_title => (:key_title, :label_title, :leg_title), ) @test Plots._subplot_defaults[:legend_font_family] == :match diff --git a/test/test_recipes.jl b/test/test_recipes.jl index 00298bc2d..89a42b1d2 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -102,9 +102,9 @@ with(:gr) do plot!(p, x, y; linestyle = :dash) yerror!(p, x, y; yerror, linestyle = :dot) @test length(p.series_list) == 3 - @test p[1][1][:line_style] == :solid - @test p[1][2][:line_style] == :dash - @test p[1][3][:line_style] == :dot + @test p[1][1][:line_style] == :solid + @test p[1][2][:line_style] == :dash + @test p[1][3][:line_style] == :dot end @testset "parametric" begin