diff --git a/NEWS.md b/NEWS.md index fcb363c42..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, :markersize, :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/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/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/Plots.jl b/src/Plots.jl index e485cd918..724668924 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..a62cba8f6 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -6,22 +6,22 @@ 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.", - :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).", - :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.", - :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`.", - :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.", + :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.", + :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).", + :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", + :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`.", + :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`", @@ -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 1e790a2ae..519b99f5e 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1,10 +1,21 @@ 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}() +const _generalAliases = ("background" => "bg", "foreground" => "fg", "pointsize" => "size", "yfill" => "fill", "alpha" => "a", "alpha" => "opacity", "alpha" => "α", "errorbar" => "error") 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 @@ -22,7 +33,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 @@ -325,22 +338,6 @@ 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, - :markersize => 4, - :markerstrokestyle => :solid, - :markerstrokewidth => 1, - :markerstrokecolor => :match, - :markerstrokealpha => nothing, :bins => :auto, # number of bins for hists :smooth => false, # regression line? :group => nothing, # groupby vector @@ -562,43 +559,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) = filter((x) -> x.second == val, aliasMap) |> keys |> collect |> sort # ----------------------------------------------------------------------------- -# 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, - :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) @@ -608,11 +568,6 @@ 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(:markerstrokewidth, :msw, :mswidth) -add_aliases(:fillcolor, :fc, :fcolor, :fcolour, :fillcolour) add_aliases( :background_color, @@ -827,10 +782,6 @@ 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(:markerstrokealpha, :msa, :msalpha, :msα, :markerstrokeopacity, :msopacity) -add_aliases(:fillalpha, :fa, :falpha, :fα, :fillopacity, :fopacity) # axes attributes add_axes_aliases(:guide, :label, :lab, :l; generic = false) @@ -910,15 +861,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(:marker, :m, :mark) -add_aliases(:markershape, :shape) -add_aliases(:markersize, :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(:group, :g, :grouping) add_aliases(:bins, :bin, :nbin, :nbins, :nb) add_aliases(:ribbon, :rib) @@ -1121,39 +1067,39 @@ 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) + 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 # 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 @@ -1161,77 +1107,77 @@ end function processMarkerArg(plotattributes::AKW, arg) # markershape if allShapes(arg) - plotattributes[:markershape] = arg + plotattributes[:marker_shape] = 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[:markerstrokecolor] = + 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[: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 + plotattributes[:marker_size] = arg # markercolor - elseif !handleColors!(plotattributes, arg, :markercolor) + elseif !handleColors!(plotattributes, arg, :marker_color) @warn "Skipped marker arg $arg." end 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 @@ -1369,9 +1315,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 @@ -1498,15 +1444,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 @@ -1588,7 +1534,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) @@ -1624,10 +1570,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) @@ -2047,8 +1993,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 @@ -2082,27 +2028,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, :yfill_alpha) 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 @@ -2111,7 +2057,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 @@ -2127,30 +2073,30 @@ 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) + ensure_gradient!(plotattributes, :yfill_color, :yfill_alpha) end # 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 @@ -2173,15 +2119,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) +macro add_attributes(level, expr, args...) + match_table = :(:match = ()) + 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 = eval(arg.args[2]) + 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 === :<: @@ -2189,17 +2148,23 @@ macro add_attributes(level, expr, match_table) end key_dict = KW() + original = copy(expr) _splitdef!(expr.args[3], key_dict) + exp_keys = Symbol[] + keys = Symbol[] insert_block = Expr(:block) for (key, value) in key_dict # e.g. _series_defualts[key] = value exp_key = Symbol(lowercase(string(T)), "_", key) + push!(exp_keys, exp_key) + push!(keys, key) pl_key = makeplural(exp_key) if QuoteNode(exp_key) in match_table.args[2].args value = QuoteNode(:match) end field = QuoteNode(Symbol("_", level, "_defaults")) + aliases = get(alias_dict, exp_key, nothing) push!( insert_block.args, Expr( @@ -2210,16 +2175,26 @@ macro add_attributes(level, expr, match_table) :(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 - $expr + Base.@kwdef $original + Base.propertynames(::Type{$T}) = $(Tuple(exp_keys)) + attributes(::Type{$T}) = $(Tuple(keys)) $insert_block end |> esc end diff --git a/src/axes.jl b/src/axes.jl index 79c1949d0..19d8cd946 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -455,7 +455,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 @@ -514,7 +514,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 9af12124b..4bccaf0ba 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -304,21 +304,21 @@ const _gr_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :fillrange, - :fillcolor, - :fillalpha, - :fillstyle, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :yfill_range, + :yfill_color, + :yfill_alpha, + :yfill_style, :bins, :layout, :title, @@ -436,21 +436,21 @@ const _plotly_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :markerstrokestyle, - :fillrange, - :fillcolor, - :fillalpha, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :marker_stroke_style, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :title, :titlelocation, @@ -561,21 +561,21 @@ const _pgfplots_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :markerstrokestyle, - :fillrange, - :fillcolor, - :fillalpha, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :marker_stroke_style, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, # :bar_width, :bar_edges, :title, @@ -676,21 +676,21 @@ const _pyplot_attr = merge_with_base_supported([ :foreground_color_guide, :foreground_color_text, :label, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :fillrange, - :fillcolor, - :fillalpha, - :fillstyle, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :yfill_range, + :yfill_color, + :yfill_alpha, + :yfill_style, :bins, :bar_width, :bar_edges, @@ -797,16 +797,16 @@ const _gaston_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - # :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokestyle, - # :fillrange, :fillcolor, :fillalpha, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + # :marker_stroke_width, :marker_stroke_color, :marker_stroke_alpha, :marker_stroke_style, + # :yfill_range, :yfill_color, :yfill_alpha, # :bins, # :bar_width, :bar_edges, :title, @@ -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,20 +977,20 @@ const _hdf5_attr = merge_with_base_supported([ :foreground_color_guide, :foreground_color_text, :label, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :fillrange, - :fillcolor, - :fillalpha, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :bar_width, :bar_edges, @@ -1082,20 +1082,20 @@ const _inspectdr_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :markerstrokestyle, #Causes warning not to have it... what is this? - :fillcolor, - :fillalpha, #:fillrange, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :marker_stroke_style, #Causes warning not to have it... what is this? + :yfill_color, + :yfill_alpha, #:yfill_range, # :bins, :bar_width, :bar_edges, :bar_position, :title, :titlelocation, @@ -1184,20 +1184,20 @@ const _pgfplotsx_attr = merge_with_base_supported([ :label, :seriescolor, :seriesalpha, - :linecolor, - :linestyle, - :linewidth, - :linealpha, - :markershape, - :markercolor, - :markersize, - :markeralpha, - :markerstrokewidth, - :markerstrokecolor, - :markerstrokealpha, - :fillrange, - :fillcolor, - :fillalpha, + :line_color, + :line_style, + :line_width, + :line_alpha, + :marker_shape, + :marker_color, + :marker_size, + :marker_alpha, + :marker_stroke_width, + :marker_stroke_color, + :marker_stroke_alpha, + :yfill_range, + :yfill_color, + :yfill_alpha, :bins, :layout, :title, diff --git a/src/backends/deprecated/pgfplots.jl b/src/backends/deprecated/pgfplots.jl index 3e992dba8..2c241a63a 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( @@ -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 @@ -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 (:markercolor, :fillcolor, :linecolor) + 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 67d28f681..eb4e5a934 100644 --- a/src/backends/gaston.jl +++ b/src/backends/gaston.jl @@ -222,7 +222,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 @@ -296,7 +296,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) @@ -305,7 +305,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) @@ -523,15 +523,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)), - _cycle(series[:markersize], i) * 1.3 / 5, - gaston_color(get_markercolor(series, clims, i), get_markeralpha(series, i)), + gaston_marker(_cycle(series[:marker_shape], i), get_marker_alpha(series, i)), + _cycle(series[:marker_size], i) * 1.3 / 5, + 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 13693b9d0..ec99fa4ff 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -368,9 +368,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 @@ -385,8 +385,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 @@ -582,10 +582,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) @@ -1000,7 +1000,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) lfps = sp[:legend_font_pointsize] gr_set_line(lfps / 8, get_linestyle(series), lc, sp) @@ -1008,7 +1008,7 @@ function gr_add_legend(sp, leg, viewport_area) 0.5leg.width_factor, 3.5leg.width_factor, 0.4leg.dy, 0.4leg.dy if ( - (st === :shape || series[:fillrange] !== nothing) && + (st === :shape || series[:yfill_range] !== nothing) && series[:ribbon] === nothing ) (fc = get_fillcolor(series, clims)) |> gr_set_fill @@ -1019,30 +1019,30 @@ function gr_add_legend(sp, leg, viewport_area) y = [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 maxmarkersize = Inf if st in (:path, :straightline, :path3d) - gr_set_transparency(lc, get_linealpha(series)) - # This is to prevent that linestyle is obscured by large markers. - # We are trying to get markers to not be larger than half the line length. + gr_set_transparency(lc, get_line_alpha(series)) + # This is to prevent that linestyle is obscured by large markers. + # We are trying to get markers to not be larger than half the line length. # 1 / leg.dy translates width_factor to line length units (important in the context of size kwarg) # gr_legend_marker_to_line_factor is an empirical constant to translate between line length unit and marker size unit maxmarkersize = gr_legend_marker_to_line_factor[] * 0.5(rgt - lft) / leg.dy - if series[:fillrange] === nothing || series[:ribbon] !== nothing + if series[:yfill_range] === nothing || series[:ribbon] !== nothing GR.polyline([xpos - rgt, xpos - lft], [ypos, ypos]) else GR.polyline([xpos - rgt, xpos - lft], [ypos + bot, ypos + top]) end end - if (msh = series[:markershape]) !== :none - msz = first(series[:markersize]) - msw = first(series[:markerstrokewidth]) + if (msh = series[:marker_shape]) !== :none + msz = first(series[:marker_size]) + msw = first(series[:marker_stroke_width]) gr_draw_marker( series, xpos - 2leg.width_factor, @@ -1611,7 +1611,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 @@ -1635,14 +1635,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 @@ -1706,9 +1706,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 @@ -1728,12 +1728,12 @@ 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) - (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 @@ -1777,9 +1777,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 @@ -1788,14 +1788,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 + if series[:yfill_range] !== 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 @@ -1847,15 +1847,15 @@ 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) 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 !")) @@ -1864,7 +1864,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 @@ -1876,18 +1876,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 dfab5d44b..61af8a7fe 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: @@ -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,28 +290,28 @@ 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 # 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[:markershape]), - size = _inspectdr_mapglyphsize(series[:markersize]), + shape = _inspectdr_mapglyph(series[:marker_shape]), + size = _inspectdr_mapglyphsize(series[:marker_size]), 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..c04fd5f70 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...), @@ -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) ) @@ -338,10 +338,10 @@ 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 + msize = opt[:marker_size] * scale_factor path = join( map((x, y) -> "($(x * msize), $(y * msize))", marker.x, marker.y), " -- ", @@ -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 @@ -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), @@ -935,9 +935,9 @@ function pgfx_marker(plotattributes, i = 1) mark_size = pgfx_thickness_scaling(plotattributes) * 0.75 * - _cycle(plotattributes[:markersize], i) - mark_freq = if !any(isnan, plotattributes[:y]) && plotattributes[:markershape] isa AVec - length(plotattributes[:markershape]) + _cycle(plotattributes[:marker_size], i) + mark_freq = if !any(isnan, plotattributes[:y]) && plotattributes[:marker_shape] isa AVec + length(plotattributes[:marker_shape]) else 1 end @@ -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 35958bc14..dd20dfc7c 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,11 +540,11 @@ 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) && - (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 @@ -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,16 +609,16 @@ 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) 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 @@ -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], - :size => 2_cycle(series[:markersize], inds), + get_plotly_marker(series[:marker_shape], string(series[:marker_shape])), + # :opacity => series[:marker_alpha], + :size => 2_cycle(series[:marker_size], 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( @@ -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 @@ -742,15 +742,15 @@ 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)), ), ), ) - if series[:markerstrokewidth] > 0 + if series[:marker_stroke_width] > 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,11 +778,11 @@ 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) && - (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] @@ -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,15 +859,15 @@ 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), + :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 @@ -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 @@ -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 df0061f1b..6156f50e9 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -242,11 +242,11 @@ 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))) + py_colormap(cgrad(series[:yfill_color], 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)), - s = py_thickness_scale(plt, _cycle(series[:markersize], i)) .^ 2, + marker = py_marker(_cycle(series[:marker_shape], i)), + s = py_thickness_scale(plt, _cycle(series[:marker_size], 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,15 +529,15 @@ 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]), - alpha = series[:fillalpha], + linewidths = py_thickness_scale(plt, series[:line_width]), + alpha = series[:yfill_alpha], cmap = py_fillcolormap(series), # applies to the pcolorfast object zorder = series[:series_plotindex], extrakw..., @@ -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 @@ -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) @@ -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,17 +683,17 @@ 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)), - facecolor = py_color(series[:fillcolor]), + linewidths = py_thickness_scale(plt, series[:line_width]), + edgecolor = py_color(get_line_color(series)), + 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._edgecolors2d = py_color(get_linecolor(series)) + handle._facecolors2d = py_color(series[:yfill_color]) + handle._edgecolors2d = py_color(get_line_color(series)) push!(handles, handle) end @@ -740,8 +740,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) label = series[:label], zorder = series[:series_plotindex], cmap = py_fillcolormap(series), - alpha = series[:fillalpha], - # edgecolors = (series[:linewidth] > 0 ? py_linecolor(series) : "face"), + alpha = series[:yfill_alpha], + # 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) @@ -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 @@ -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) @@ -1464,10 +1464,10 @@ 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) + if series[:seriestype] === :shape || series[:yfill_range] !== nothing + 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) @@ -1506,8 +1506,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, @@ -1518,20 +1518,20 @@ 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, 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/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index 29d053378..c1084d9ee 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -218,7 +218,7 @@ function addUnicodeSeries!( zlabel = sp[:colorbar_title], colormap = colormap === :none ? up_cmap(series) : colormap, colorbar = hascolorbar(sp), - color = st === :wireframe ? up_color(get_linecolor(series, 1)) : nothing, + color = st === :wireframe ? up_color(get_line_color(series, 1)) : nothing, zscale = zscale, lines = lines, ) @@ -234,9 +234,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 @@ -245,7 +245,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..dc3d0e1ab 100644 --- a/src/components.jl +++ b/src/components.jl @@ -551,8 +551,8 @@ 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[:markersize] = msize + series[:marker_shape] = shapes + series[:marker_size] = msize end nothing end @@ -832,4 +832,62 @@ 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 + +@add_attributes series struct Line + style = :solid + width = :auto + color = :auto + alpha = nothing +end :aliases = Dict( + :line_color => (:lc, :lcolor, :lcolour, :line_colour), + :line_alpha => (:lalpha,), + :line_width => (:w, :width, :lw), + :line_style => (:s, :style, :ls), + +) + +### Marker + +@add_attributes series struct Marker + shape = :none + color = :match + alpha = nothing + stroke::Line = Line(:solid, 1, :match, nothing) + size = 4 +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), +) + +for letter in (:X, :Y, :Z) + ### Errorbars + @eval @add_attributes series struct $(Symbol(letter, :ErrorBar)) + marker::Marker = Marker(shape = $(QuoteNode(getproperty(( X = :vline, Y = :hline, Z = :hline), letter)))) + line::Line = Line() + end + + ### Fills + @eval @add_attributes series struct $(Symbol(letter, :Fill)) + 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) + ) +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 fcf11d794..42bbb18f1 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, ), @@ -164,7 +164,7 @@ function RecipesPipeline.process_sliced_series_attributes!(plt::Plots.Plot, kw_l for kw in kw_list 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]) @@ -174,7 +174,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 @@ -344,11 +344,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/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 diff --git a/src/recipes.jl b/src/recipes.jl index 54b4ca6b1..22d0fd71e 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -46,25 +46,25 @@ 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, + :yfill_color, + :yfill_alpha, :fill_z, - :markercolor, - :markeralpha, - :markershape, + :marker_color, + :marker_alpha, + :marker_shape, :marker_z, - :markerstrokecolor, - :markerstrokealpha, + :marker_stroke_color, + :marker_stroke_alpha, :xerror, :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,10 +218,10 @@ 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[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -243,10 +243,10 @@ 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[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -268,10 +268,10 @@ 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[:markershape] !== :none + if plotattributes[:marker_shape] !== :none @series begin seriestype := :scatter x := x @@ -292,7 +292,7 @@ end # create vertical line segments from fill @recipe function f(::Type{Val{:sticks}}, x, y, z) # COV_EXCL_LINE n = length(x) - fr = plotattributes[:fillrange] + fr = plotattributes[:yfill_range] if fr === nothing sp = plotattributes[:subplot] fr = if sp[:yaxis][:scale] === :identity @@ -321,7 +321,7 @@ end fillrange := nothing seriestype := :path if ( - plotattributes[:linecolor] === :auto && + plotattributes[:line_color] === :auto && plotattributes[:marker_z] !== nothing && plotattributes[:line_z] === nothing ) @@ -329,7 +329,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 @@ -368,7 +368,7 @@ end @recipe function f(::Type{Val{:curves}}, x, y, z; npoints = 30) # COV_EXCL_LINE args = z !== nothing ? (x, y, z) : (x, y) newx, newy = zeros(0), zeros(0) - fr = plotattributes[:fillrange] + fr = plotattributes[:yfill_range] newfr = fr !== nothing ? zeros(0) : nothing newz = z !== nothing ? zeros(0) : nothing @@ -433,7 +433,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) @@ -518,7 +518,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 @@ -690,7 +690,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) @@ -971,7 +971,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 @@ -1010,12 +1010,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 @@ -1093,28 +1093,15 @@ end # Error Bars @attributes function error_style!(plotattributes::AKW) - # errorbar color should soley determined by markerstrokecolor haskey(plotattributes, :marker_z) && reset_kw!(plotattributes, :marker_z) haskey(plotattributes, :line_z) && reset_kw!(plotattributes, :line_z) - - msc = if (msc = plotattributes[:markerstrokecolor]) === :match - plotattributes[:subplot][:foreground_color_subplot] - elseif msc === :auto - get_series_color( - plotattributes[:linecolor], - plotattributes[:subplot], - plotattributes[:series_plotindex], - plotattributes[:seriestype], - ) - else - msc + type = getproperty(Plots, Symbol("$(uppercase(first(string(plotattributes[:seriestype]))))ErrorBar")) + for (tproperty, property) in zip(attributes(type), propertynames(type)) + tproperty == :marker && continue #FIXME + tproperty == :line && continue #FIXME + tproperty --> plotattributes[property] end - seriestype := :path - markerstrokecolor --> msc - markercolor --> msc - linecolor --> msc - linewidth --> plotattributes[:markerstrokewidth] label --> "" end @@ -1148,7 +1135,7 @@ clamp_to_eps!(ary) = (replace!(x -> x <= 0.0 ? Base.eps(Float64) : x, ary); noth @recipe function f(::Type{Val{:xerror}}, x, y, z) # COV_EXCL_LINE error_style!(plotattributes) - markershape --> :vline + markershape --> plotattributes[:xerrorbar_marker_shape] xerr = error_zipit(plotattributes[:xerror]) if z === nothing plotattributes[:x], plotattributes[:y] = error_coords(xerr, x, y) @@ -1165,7 +1152,7 @@ end @recipe function f(::Type{Val{:yerror}}, x, y, z) # COV_EXCL_LINE error_style!(plotattributes) - markershape --> :hline + markershape --> plotattributes[:yerrorbar_marker_shape] yerr = error_zipit(plotattributes[:yerror]) if z === nothing plotattributes[:y], plotattributes[:x] = error_coords(yerr, y, x) @@ -1182,7 +1169,7 @@ end @recipe function f(::Type{Val{:zerror}}, x, y, z) # COV_EXCL_LINE error_style!(plotattributes) - markershape --> :hline + markershape --> plotattributes[:zerrorbar_marker_shape] if z !== nothing zerr = error_zipit(plotattributes[:zerror]) plotattributes[:z], plotattributes[:x], plotattributes[:y] = @@ -1354,7 +1341,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 @@ -1419,7 +1406,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 ae483bd99..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) @@ -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 6c5b82204..977285218 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -369,8 +369,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 @@ -410,7 +410,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") @@ -423,17 +423,17 @@ 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) + 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[: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)) @@ -460,15 +460,15 @@ 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[: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] + series[:yfill_color] end end @@ -479,35 +479,35 @@ 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_fillstyle(series, i::Int = 1) = _cycle(series[:fillstyle], 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[:yfill_style], i) function get_markerstrokecolor(series, i::Int = 1) - msc = series[:markerstrokecolor] + msc = series[:marker_stroke_color] 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, :seriesalpha, - :linecolor, - :linealpha, - :linewidth, - :linestyle, - :fillcolor, - :fillalpha, - :fillstyle, - :markercolor, - :markeralpha, - :markersize, - :markerstrokecolor, - :markerstrokealpha, - :markerstrokewidth, - :markershape, + :line_color, + :line_alpha, + :line_width, + :line_style, + :yfill_color, + :yfill_alpha, + :yfill_style, + :marker_color, + :marker_alpha, + :marker_size, + :marker_stroke_color, + :marker_stroke_alpha, + :marker_stroke_width, + :marker_shape, ) const _segmenting_array_attributes = :line_z, :fill_z, :marker_z diff --git a/test/test_args.jl b/test/test_args.jl index a8f0d1c6d..734dac7ae 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 @@ -50,8 +51,19 @@ end :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_title => (:key_title, :label_title, :leg_title), ) - @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[:bgcolourlegend] == :legend_background_color + @test Plots._keyAliases[:bgcolour_legend] == :legend_background_color + @test Plots._keyAliases[:legendfontsize] == :legend_font_pointsize + @test haskey(Plots._series_defaults, :zerrorbar_marker_shape) end @testset "aspect_ratio" begin 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 a5f7bd776..8e3f0d391 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -151,11 +151,11 @@ 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) for i in axes(data4, 1) - for attribute in (:fillrange, :ribbon) + for attribute in (:yfill_range, :ribbon) get_attr(pl) = pl[1][i][attribute] @test plot(data4; NamedTuple{tuple(attribute)}(0)...) |> get_attr == 0 @test plot(data4; NamedTuple{tuple(attribute)}(Ref([1, 2]))...) |> get_attr == @@ -273,7 +273,7 @@ end 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 diff --git a/test/test_recipes.jl b/test/test_recipes.jl index f20276d1d..c30fe426b 100644 --- a/test/test_recipes.jl +++ b/test/test_recipes.jl @@ -1,4 +1,4 @@ -using OffsetArrays +using Plots, Test, OffsetArrays @testset "User recipes" begin struct LegendPlot end @@ -85,9 +85,12 @@ end 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 + @test_nowarn p2 = plot(1:10,1:10,yerr=0.5,shape=:o, yerror_markershape=:o) + @test p2[1][1][:marker_shape] = :o + @test p2[1][2][:marker_shape] = :o end @testset "parametric" begin