From 11e9eb3aa354a5ea07e608cb9d5c35bdbe19efdb Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 23 Apr 2017 20:30:48 +0200 Subject: [PATCH 01/68] allow Int as input type for the ticks attribute to set the desired number of ticks --- src/axes.jl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 7af2d7c5..dae525c3 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -188,6 +188,23 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) k_min = 5, # minimum number of ticks k_max = 8, # maximum number of ticks )[1] + elseif typeof(ticks) <: Int + # only return ticks within the axis limits + filter( + ti -> sf(amin) <= ti <= sf(amax), + optimize_ticks( + sf(amin), + sf(amax); + # TODO: find a better configuration to return the chosen number + # of ticks + k_min = ticks + 1, # minimum number of ticks + k_max = ticks + 2, # maximum number of ticks + k_ideal = ticks + 2, + # `strict_span = false` rewards cases where the span of the + # chosen ticks is not too much bigger than amin - amax: + strict_span = false, + )[1] + ) else map(sf, filter(t -> amin <= t <= amax, ticks)) end @@ -226,7 +243,7 @@ function get_ticks(axis::Axis) elseif ticks == :auto # compute optimal ticks and labels optimal_ticks_and_labels(axis) - elseif typeof(ticks) <: AVec + elseif typeof(ticks) <: Union{AVec, Int} # override ticks, but get the labels optimal_ticks_and_labels(axis, ticks) elseif typeof(ticks) <: NTuple{2} From a602309a02c72359227c1d1d68635cf5b1d37762 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 30 Apr 2017 19:02:42 +0200 Subject: [PATCH 02/68] wip let axis limits expand --- src/axes.jl | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index dae525c3..9dfa18a9 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -181,32 +181,32 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) end # get a list of well-laid-out ticks - scaled_ticks = if ticks == nothing - optimize_ticks( + if ticks == nothing + scaled_ticks = optimize_ticks( sf(amin), sf(amax); k_min = 5, # minimum number of ticks k_max = 8, # maximum number of ticks - )[1] + )[1], sf(amin), sf(amax) elseif typeof(ticks) <: Int - # only return ticks within the axis limits - filter( - ti -> sf(amin) <= ti <= sf(amax), - optimize_ticks( - sf(amin), - sf(amax); - # TODO: find a better configuration to return the chosen number - # of ticks - k_min = ticks + 1, # minimum number of ticks - k_max = ticks + 2, # maximum number of ticks - k_ideal = ticks + 2, - # `strict_span = false` rewards cases where the span of the - # chosen ticks is not too much bigger than amin - amax: - strict_span = false, - )[1] + scaled_ticks, viewmin, viewmax = optimize_ticks( + sf(amin), + sf(amax); + # TODO: find a better configuration to return the chosen number + # of ticks + k_min = ticks, # minimum number of ticks + k_max = ticks, # maximum number of ticks + k_ideal = ticks, + # k_min = ticks + 1, # minimum number of ticks + # k_max = ticks + 2, # maximum number of ticks + # k_ideal = ticks + 2, + # `strict_span = false` rewards cases where the span of the + # chosen ticks is not too much bigger than amin - amax: + strict_span = false, ) + axis[:lims] = map(invscalefunc(scale), (viewmin, viewmax)) else - map(sf, filter(t -> amin <= t <= amax, ticks)) + scaled_ticks = map(sf, (filter(t -> amin <= t <= amax, ticks), amin, amax)) end unscaled_ticks = map(invscalefunc(scale), scaled_ticks) @@ -503,10 +503,10 @@ end # compute the line segments which should be drawn for this axis function axis_drawing_info(sp::Subplot) xaxis, yaxis = sp[:xaxis], sp[:yaxis] - xmin, xmax = axis_limits(xaxis) - ymin, ymax = axis_limits(yaxis) xticks = get_ticks(xaxis) yticks = get_ticks(yaxis) + xmin, xmax = axis_limits(xaxis) + ymin, ymax = axis_limits(yaxis) spine_segs = Segments(2) grid_segs = Segments(2) From 93d16a27c1cb67e7305360429cea15b80eb3f4dc Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 30 Apr 2017 19:27:01 +0200 Subject: [PATCH 03/68] undo unnecessary changes --- src/axes.jl | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 9dfa18a9..276d7374 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -187,26 +187,21 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) sf(amax); k_min = 5, # minimum number of ticks k_max = 8, # maximum number of ticks - )[1], sf(amin), sf(amax) + )[1] elseif typeof(ticks) <: Int scaled_ticks, viewmin, viewmax = optimize_ticks( sf(amin), sf(amax); - # TODO: find a better configuration to return the chosen number - # of ticks k_min = ticks, # minimum number of ticks k_max = ticks, # maximum number of ticks k_ideal = ticks, - # k_min = ticks + 1, # minimum number of ticks - # k_max = ticks + 2, # maximum number of ticks - # k_ideal = ticks + 2, # `strict_span = false` rewards cases where the span of the # chosen ticks is not too much bigger than amin - amax: strict_span = false, ) axis[:lims] = map(invscalefunc(scale), (viewmin, viewmax)) else - scaled_ticks = map(sf, (filter(t -> amin <= t <= amax, ticks), amin, amax)) + scaled_ticks = map(sf, (filter(t -> amin <= t <= amax, ticks))) end unscaled_ticks = map(invscalefunc(scale), scaled_ticks) @@ -503,10 +498,10 @@ end # compute the line segments which should be drawn for this axis function axis_drawing_info(sp::Subplot) xaxis, yaxis = sp[:xaxis], sp[:yaxis] - xticks = get_ticks(xaxis) - yticks = get_ticks(yaxis) xmin, xmax = axis_limits(xaxis) ymin, ymax = axis_limits(yaxis) + xticks = get_ticks(xaxis) + yticks = get_ticks(yaxis) spine_segs = Segments(2) grid_segs = Segments(2) From bad2ef63c6c4794ee9be1525942667fcb6e2618d Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 21 May 2017 23:44:12 +0200 Subject: [PATCH 04/68] fix passing ticks tuple on 0.6 --- src/axes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 276d7374..8aaa1908 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -241,7 +241,7 @@ function get_ticks(axis::Axis) elseif typeof(ticks) <: Union{AVec, Int} # override ticks, but get the labels optimal_ticks_and_labels(axis, ticks) - elseif typeof(ticks) <: NTuple{2} + elseif typeof(ticks) <: NTuple{2, Any} # assuming we're passed (ticks, labels) ticks else From dd526e00ab74ed936ee15df24a1e26e8781d100a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 21 May 2017 23:47:26 +0200 Subject: [PATCH 05/68] undo: fix passing ticks tuple on 0.6 --- src/axes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 8aaa1908..276d7374 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -241,7 +241,7 @@ function get_ticks(axis::Axis) elseif typeof(ticks) <: Union{AVec, Int} # override ticks, but get the labels optimal_ticks_and_labels(axis, ticks) - elseif typeof(ticks) <: NTuple{2, Any} + elseif typeof(ticks) <: NTuple{2} # assuming we're passed (ticks, labels) ticks else From 26a56c3105c7f45f4b8ca7f1be125895cce368d1 Mon Sep 17 00:00:00 2001 From: john verzani Date: Thu, 27 Jul 2017 15:48:52 -0400 Subject: [PATCH 06/68] Update appveyor.yml add testing on v0.6 with 32 and 64 bit. --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index c0464e36..5a846a42 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,8 @@ environment: matrix: - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" From 8c3c07acb7c14b5c942ad966485a01ccae4b046c Mon Sep 17 00:00:00 2001 From: john verzani Date: Thu, 27 Jul 2017 16:56:17 -0400 Subject: [PATCH 07/68] Update appveyor.yml remove v0.5 testing from appveyor --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 5a846a42..cc07d84a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,5 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" From 9f0117d914c3a558a08b800a7fd58f2fd64f87c1 Mon Sep 17 00:00:00 2001 From: john verzani Date: Tue, 1 Aug 2017 15:48:12 -0400 Subject: [PATCH 08/68] Update README.md add appveyor badge. (But how does appveyor get run, as it doesn't seem to be current) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b88fe561..72a82007 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Plots [![Build Status](https://travis-ci.org/JuliaPlots/Plots.jl.svg?branch=master)](https://travis-ci.org/JuliaPlots/Plots.jl) +[![Build status](https://ci.appveyor.com/api/projects/status/github/tbreloff/plots.jl?branch=master&svg=true)](https://ci.appveyor.com/project/tbreloff/plots-jl) [![Join the chat at https://gitter.im/tbreloff/Plots.jl](https://badges.gitter.im/tbreloff/Plots.jl.svg)](https://gitter.im/tbreloff/Plots.jl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From 6b814b8dcadd2e4c9229a951f2d27e42f26a2ee7 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 10 Aug 2017 16:32:24 +0200 Subject: [PATCH 09/68] initial commit mostly a copy of #695 --- src/Plots.jl | 6 ++++++ src/arg_desc.jl | 2 +- src/args.jl | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e7c7fc66..d320df7c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -52,6 +52,8 @@ export yflip!, xaxis!, yaxis!, + xgrid!, + ygrid!, xlims, ylims, @@ -213,6 +215,8 @@ xflip!(flip::Bool = true; kw...) = plot!(; xflip = flip yflip!(flip::Bool = true; kw...) = plot!(; yflip = flip, kw...) xaxis!(args...; kw...) = plot!(; xaxis = args, kw...) yaxis!(args...; kw...) = plot!(; yaxis = args, kw...) +xgrid!(grid::Bool = true; kw...) = plot!(; xgrid = grid, kw...) +ygrid!(grid::Bool = true; kw...) = plot!(; ygrid = grid, kw...) let PlotOrSubplot = Union{Plot, Subplot} title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) @@ -230,6 +234,8 @@ let PlotOrSubplot = Union{Plot, Subplot} ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; xticks = (ticks,labels), kw...) yticks!{T<:Real,S<:AbstractString}(plt::PlotOrSubplot, ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; yticks = (ticks,labels), kw...) + xgrid!(plt::PlotOrSubplot, grid::Bool = true; kw...) = plot!(plt; xgrid = grid, kw...) + ygrid!(plt::PlotOrSubplot, grid::Bool = true; kw...) = plot!(plt; ygrid = grid, kw...) annotate!(plt::PlotOrSubplot, anns...; kw...) = plot!(plt; annotation = anns, kw...) annotate!{T<:Tuple}(plt::PlotOrSubplot, anns::AVec{T}; kw...) = plot!(plt; annotation = anns, kw...) xflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; xflip = flip, kw...) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index f244ff99..571400a7 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -84,7 +84,6 @@ const _arg_desc = KW( :colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)", :clims => "`:auto` or NTuple{2,Number}. Fixes the limits of the colorbar.", :legendfont => "Font. Font of legend items.", -:grid => "Bool. Show the grid lines?", :annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String or PlotText (created with `text(args...)`) Add one-off text annotations at the x,y coordinates.", :projection => "Symbol or String. '3d' or 'polar'", :aspect_ratio => "Symbol (:equal) or Number. Plot area is resized so that 1 y-unit is the same size as `apect_ratio` x-units.", @@ -111,5 +110,6 @@ const _arg_desc = KW( :foreground_color_text => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of tick labels.", :foreground_color_guide => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of axis guides (axis labels).", :mirror => "Bool. Switch the side of the tick labels (right or top).", +:grid => "Bool. Show the grid lines?", ) diff --git a/src/args.jl b/src/args.jl index ea4f8627..cf023191 100644 --- a/src/args.jl +++ b/src/args.jl @@ -247,7 +247,6 @@ const _subplot_defaults = KW( :background_color_inside => :match, # background inside grid :foreground_color_subplot => :match, # default for other fg colors... match takes plot default :foreground_color_legend => :match, # foreground of legend - :foreground_color_grid => :match, # grid color :foreground_color_title => :match, # title color :color_palette => :auto, :legend => :best, @@ -255,7 +254,6 @@ const _subplot_defaults = KW( :colorbar => :legend, :clims => :auto, :legendfont => font(8), - :grid => true, :annotations => [], # annotation tuples... list of (x,y,annotation) :projection => :none, # can also be :polar or :3d :aspect_ratio => :none, # choose from :none or :equal @@ -285,6 +283,8 @@ const _axis_defaults = KW( :discrete_values => [], :formatter => :auto, :mirror => false, + :grid => true, + :foreground_color_grid => :match, # grid color ) const _suppress_warnings = Set{Symbol}([ From c60d66d94a3873748b8e70f15333209766a60463 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 10 Aug 2017 17:46:11 +0200 Subject: [PATCH 10/68] make it work for gr, pyplot and plotly(js) --- src/args.jl | 4 +-- src/axes.jl | 58 +++++++++++++++++++++++++----------------- src/backends/gr.jl | 28 ++++++++++++-------- src/backends/plotly.jl | 7 ++--- src/backends/pyplot.jl | 4 +-- 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/args.jl b/src/args.jl index cf023191..0012bc7e 100644 --- a/src/args.jl +++ b/src/args.jl @@ -943,7 +943,6 @@ const _match_map = KW( :background_color_legend => :background_color_subplot, :background_color_inside => :background_color_subplot, :foreground_color_legend => :foreground_color_subplot, - :foreground_color_grid => :foreground_color_subplot, :foreground_color_title => :foreground_color_subplot, :left_margin => :margin, :top_margin => :margin, @@ -957,6 +956,7 @@ const _match_map2 = KW( :foreground_color_subplot => :foreground_color, :foreground_color_axis => :foreground_color_subplot, :foreground_color_border => :foreground_color_subplot, + :foreground_color_grid => :foreground_color_subplot, :foreground_color_guide => :foreground_color_subplot, :foreground_color_text => :foreground_color_subplot, ) @@ -1091,7 +1091,6 @@ function _update_subplot_colors(sp::Subplot) # foreground colors color_or_nothing!(sp.attr, :foreground_color_subplot) color_or_nothing!(sp.attr, :foreground_color_legend) - color_or_nothing!(sp.attr, :foreground_color_grid) color_or_nothing!(sp.attr, :foreground_color_title) return end @@ -1143,6 +1142,7 @@ function _update_axis_colors(axis::Axis) color_or_nothing!(axis.d, :foreground_color_border) color_or_nothing!(axis.d, :foreground_color_guide) color_or_nothing!(axis.d, :foreground_color_text) + color_or_nothing!(axis.d, :foreground_color_grid) return end diff --git a/src/axes.jl b/src/axes.jl index e53d3ccb..6ac60b7c 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -490,38 +490,50 @@ function axis_drawing_info(sp::Subplot) ymin, ymax = axis_limits(yaxis) xticks = get_ticks(xaxis) yticks = get_ticks(yaxis) - spine_segs = Segments(2) - grid_segs = Segments(2) + xspine_segs = Segments(2) + yspine_segs = Segments(2) + xgrid_segs = Segments(2) + ygrid_segs = Segments(2) + + f = scalefunc(yaxis[:scale]) + invf = invscalefunc(yaxis[:scale]) + t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) + t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) if !(xaxis[:ticks] in (nothing, false)) - f = scalefunc(yaxis[:scale]) - invf = invscalefunc(yaxis[:scale]) - t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) - t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) - - push!(spine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine - # push!(spine_segs, (xmin,ymax), (xmax,ymax)) # top spine + push!(xspine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine + # push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine for xtick in xticks[1] - push!(spine_segs, (xtick, ymin), (xtick, t1)) # bottom tick - push!(grid_segs, (xtick, t1), (xtick, t2)) # vertical grid - # push!(spine_segs, (xtick, ymax), (xtick, t2)) # top tick + push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick + # push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick end end + if !(xaxis[:grid] in (nothing, false)) + for xtick in xticks[1] + push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid + end + end + + f = scalefunc(xaxis[:scale]) + invf = invscalefunc(xaxis[:scale]) + t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) + t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) + if !(yaxis[:ticks] in (nothing, false)) - f = scalefunc(xaxis[:scale]) - invf = invscalefunc(xaxis[:scale]) - t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) - t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) - - push!(spine_segs, (xmin,ymin), (xmin,ymax)) # left spine - # push!(spine_segs, (xmax,ymin), (xmax,ymax)) # right spine + push!(yspine_segs, (xmin,ymin), (xmin,ymax)) # left spine + # push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine for ytick in yticks[1] - push!(spine_segs, (xmin, ytick), (t1, ytick)) # left tick - push!(grid_segs, (t1, ytick), (t2, ytick)) # horizontal grid - # push!(spine_segs, (xmax, ytick), (t2, ytick)) # right tick + push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick + # push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick end end - xticks, yticks, spine_segs, grid_segs + if !(yaxis[:grid] in (nothing, false)) + for ytick in yticks[1] + push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + end + end + + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 80b52822..e2e42a26 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -691,10 +691,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1]) # GR.setlinetype(GR.LINETYPE_DOTTED) - if sp[:grid] - GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2) - GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) - end + # if sp[:grid] + GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2) + GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) + # end GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) @@ -709,23 +709,31 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setwindow(xmin, xmax, ymin, ymax) end - xticks, yticks, spine_segs, grid_segs = axis_drawing_info(sp) + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = axis_drawing_info(sp) # @show xticks yticks #spine_segs grid_segs # draw the grid lines - if sp[:grid] + if !(xaxis[:grid] in (nothing, false)) # gr_set_linecolor(sp[:foreground_color_grid]) # GR.grid(xtick, ytick, 0, 0, majorx, majory) - gr_set_line(1, :dot, sp[:foreground_color_grid]) + gr_set_line(1, :dot, xaxis[:foreground_color_grid]) GR.settransparency(0.5) - gr_polyline(coords(grid_segs)...) + gr_polyline(coords(xgrid_segs)...) + end + if !(yaxis[:grid] in (nothing, false)) + gr_set_line(1, :dot, yaxis[:foreground_color_grid]) + GR.settransparency(0.5) + gr_polyline(coords(ygrid_segs)...) end GR.settransparency(1.0) # spine (border) and tick marks - gr_set_line(1, :solid, sp[:xaxis][:foreground_color_axis]) + gr_set_line(1, :solid, xaxis[:foreground_color_axis]) GR.setclip(0) - gr_polyline(coords(spine_segs)...) + gr_polyline(coords(xspine_segs)...) + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + GR.setclip(0) + gr_polyline(coords(yspine_segs)...) GR.setclip(1) if !(xticks in (nothing, false)) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9f764f4c..0a1e25aa 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -5,7 +5,8 @@ const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, :foreground_color_legend, :foreground_color_guide, - # :foreground_color_grid, :foreground_color_axis, + :foreground_color_grid, + # :foreground_color_axis, :foreground_color_text, :foreground_color_border, :foreground_color_title, :label, @@ -213,7 +214,7 @@ function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] ax = KW( :title => axis[:guide], - :showgrid => sp[:grid], + :showgrid => !(axis[:grid] in (nothing, false)), :zeroline => false, :ticks => "inside", ) @@ -230,7 +231,7 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:type] = plotly_scale(axis[:scale]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) - ax[:linecolor] = rgba_string(axis[:foreground_color_border]) + ax[:linecolor] = rgba_string(axis[:foreground_color_grid]) # lims lims = axis[:lims] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d67abfcd..4100ccbf 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1064,8 +1064,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) lab[:set_family](axis[:tickfont].family) lab[:set_rotation](axis[:rotation]) end - if sp[:grid] - fgcolor = py_color(sp[:foreground_color_grid]) + if !(axis[:grid] in (nothing, false)) + fgcolor = py_color(axis[:foreground_color_grid]) pyaxis[:grid](true, color = fgcolor, linestyle = ":") ax[:set_axisbelow](true) end From 2dd99d053a3b65eff2797f1f13bdd796f1be5d01 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 10 Aug 2017 20:49:03 +0200 Subject: [PATCH 11/68] make it work on all backends --- src/backends/glvisualize.jl | 24 ++++++++++++++++++------ src/backends/gr.jl | 13 +++++++++---- src/backends/inspectdr.jl | 16 ++++++++++------ src/backends/pgfplots.jl | 12 ++++++++---- src/backends/plotly.jl | 8 ++++---- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 3484131b..118db197 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -676,17 +676,29 @@ function text_model(font, pivot) end end function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area) - xticks, yticks, spine_segs, grid_segs = Plots.axis_drawing_info(sp) + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = Plots.axis_drawing_info(sp) xaxis = sp[:xaxis]; yaxis = sp[:yaxis] - c = Colors.color(Plots.gl_color(sp[:foreground_color_grid])) + xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid])) + ygc = Colors.color(Plots.gl_color(yaxis[:foreground_color_grid])) axis_vis = [] - if sp[:grid] - grid = draw_grid_lines(sp, grid_segs, 1f0, :dot, model, RGBA(c, 0.3f0)) + if !(xaxis[:grid] in (nothing, false)) + grid = draw_grid_lines(sp, xgrid_segs, 1f0, :dot, model, RGBA(xgc, 0.3f0)) push!(axis_vis, grid) end - if alpha(xaxis[:foreground_color_border]) > 0 - spine = draw_grid_lines(sp, spine_segs, 1f0, :solid, model, RGBA(c, 1.0f0)) + if !(yaxis[:grid] in (nothing, false)) + grid = draw_grid_lines(sp, ygrid_segs, 1f0, :dot, model, RGBA(ygc, 0.3f0)) + push!(axis_vis, grid) + end + + xac = Colors.color(Plots.gl_color(xaxis[:foreground_color_axis])) + yac = Colors.color(Plots.gl_color(yaxis[:foreground_color_axis])) + if alpha(xaxis[:foreground_color_axis]) > 0 + spine = draw_grid_lines(sp, xspine_segs, 1f0, :solid, model, RGBA(xac, 1.0f0)) + push!(axis_vis, spine) + end + if alpha(yaxis[:foreground_color_axis]) > 0 + spine = draw_grid_lines(sp, yspine_segs, 1f0, :solid, model, RGBA(yac, 1.0f0)) push!(axis_vis, spine) end fcolor = Plots.gl_color(xaxis[:foreground_color_axis]) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e2e42a26..a0a9171d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -691,10 +691,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1]) # GR.setlinetype(GR.LINETYPE_DOTTED) - # if sp[:grid] - GR.grid3d(xtick, 0, ztick, xmin, ymax, zmin, 2, 0, 2) - GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) - # end + if !(xaxis[:grid] in (nothing, false)) + GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0) + end + if !(yaxis[:grid] in (nothing, false)) + GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) + end + if !(zaxis[:grid] in (nothing, false)) + GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2) + end GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index d7ef859c..1feda4ba 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -18,7 +18,8 @@ Add in functionality to Plots.jl: const _inspectdr_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, - :foreground_color_grid, :foreground_color_legend, :foreground_color_title, + # :foreground_color_grid, + :foreground_color_legend, :foreground_color_title, :foreground_color_axis, :foreground_color_border, :foreground_color_guide, :foreground_color_text, :label, :linecolor, :linestyle, :linewidth, :linealpha, @@ -334,15 +335,18 @@ end # --------------------------------------------------------------------------- function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) - const gridon = InspectDR.GridRect(vmajor=true, hmajor=true) - const gridoff = InspectDR.GridRect() const plot = sp.o const strip = plot.strips[1] #Only 1 strip supported with Plots.jl - #No independent control of grid??? - strip.grid = sp[:grid]? gridon: gridoff - xaxis = sp[:xaxis]; yaxis = sp[:yaxis] + xgrid_show = !(xaxis[:grid] in (nothing, false)) + ygrid_show = !(yaxis[:grid] in (nothing, false)) + + strip.grid = InspectDR.GridRect( + vmajor=xgrid_show, # vminor=xgrid_show, + hmajor=ygrid_show, # hminor=ygrid_show, + ) + plot.xscale = _inspectdr_getscale(xaxis[:scale], false) strip.yscale = _inspectdr_getscale(yaxis[:scale], true) xmin, xmax = axis_limits(xaxis) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index c44c10ae..cbbd645b 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -98,7 +98,7 @@ const _pgf_series_extrastyle = KW( :xsticks => "xcomb", ) -# PGFPlots uses the anchors to define orientations for example to align left +# PGFPlots uses the anchors to define orientations for example to align left # one needs to use the right edge as anchor const _pgf_annotation_halign = KW( :center => "", @@ -121,7 +121,7 @@ function pgf_color(grad::ColorGradient) end # Generates a colormap for pgfplots based on a ColorGradient -function pgf_colormap(grad::ColorGradient) +function pgf_colormap(grad::ColorGradient) join(map(grad.colors) do c @sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c),blue(c)) end,", ") @@ -266,6 +266,11 @@ function pgf_axis(sp::Subplot, letter) push!(style, "$(letter)majorticks=false") end + # grid on or off + if !(axis[:grid] in (nothing, false)) + push!(style, "$(letter)majorgrids = true") + end + # limits # TODO: support zlims if letter != :z @@ -324,7 +329,6 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:title] = "$(sp[:title])" end - sp[:grid] && push!(style, "grid = major") if sp[:aspect_ratio] in (1, :equal) kw[:axisEqual] = "true" end @@ -360,7 +364,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:colorbar] = "true" end # goto is needed to break out of col and series for - @goto colorbar_end + @goto colorbar_end end end end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 0a1e25aa..d558d941 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -5,8 +5,7 @@ const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, :foreground_color_legend, :foreground_color_guide, - :foreground_color_grid, - # :foreground_color_axis, + :foreground_color_grid, :foreground_color_axis, :foreground_color_text, :foreground_color_border, :foreground_color_title, :label, @@ -214,6 +213,7 @@ function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] ax = KW( :title => axis[:guide], + :gridcolor => rgba_string(axis[:foreground_color_grid]), :showgrid => !(axis[:grid] in (nothing, false)), :zeroline => false, :ticks => "inside", @@ -230,8 +230,8 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) - ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) - ax[:linecolor] = rgba_string(axis[:foreground_color_grid]) + ax[:tickcolor] = rgba_string(axis[:foreground_color_axis]) + ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) # lims lims = axis[:lims] From 3c37de152d910fa8bbe63a7ef875ae9799cd739f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 10 Aug 2017 22:54:45 +0200 Subject: [PATCH 12/68] fix testimage 16 error - only add grid segments when ticks are defined --- src/axes.jl | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 6ac60b7c..cafee577 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -495,43 +495,33 @@ function axis_drawing_info(sp::Subplot) xgrid_segs = Segments(2) ygrid_segs = Segments(2) - f = scalefunc(yaxis[:scale]) - invf = invscalefunc(yaxis[:scale]) - t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) - t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) - if !(xaxis[:ticks] in (nothing, false)) + f = scalefunc(yaxis[:scale]) + invf = invscalefunc(yaxis[:scale]) + t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) + t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) + push!(xspine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine # push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine for xtick in xticks[1] push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick # push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick + !(xaxis[:grid] in (nothing, false)) && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid end end - if !(xaxis[:grid] in (nothing, false)) - for xtick in xticks[1] - push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid - end - end - - f = scalefunc(xaxis[:scale]) - invf = invscalefunc(xaxis[:scale]) - t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) - t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) - if !(yaxis[:ticks] in (nothing, false)) + f = scalefunc(xaxis[:scale]) + invf = invscalefunc(xaxis[:scale]) + t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) + t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) + push!(yspine_segs, (xmin,ymin), (xmin,ymax)) # left spine # push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine for ytick in yticks[1] push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick # push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick - end - end - - if !(yaxis[:grid] in (nothing, false)) - for ytick in yticks[1] - push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + !(yaxis[:grid] in (nothing, false)) && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid end end From 23ae99b97e119c889e3fedb67125bac7339374d5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 11 Aug 2017 12:57:11 +0200 Subject: [PATCH 13/68] undo support for foreground_color_grid and foreground_color_axis attributes in plotly(js) --- src/backends/plotly.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index d558d941..cc0aed9c 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -5,7 +5,7 @@ const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, :foreground_color_legend, :foreground_color_guide, - :foreground_color_grid, :foreground_color_axis, + # :foreground_color_grid, :foreground_color_axis, :foreground_color_text, :foreground_color_border, :foreground_color_title, :label, @@ -213,7 +213,6 @@ function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] ax = KW( :title => axis[:guide], - :gridcolor => rgba_string(axis[:foreground_color_grid]), :showgrid => !(axis[:grid] in (nothing, false)), :zeroline => false, :ticks => "inside", @@ -230,8 +229,8 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) - ax[:tickcolor] = rgba_string(axis[:foreground_color_axis]) - ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) + ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) + ax[:linecolor] = rgba_string(axis[:foreground_color_border]) # lims lims = axis[:lims] From 33a15f1e9386eaf3dedbe1e14e6feb1dda17b7a9 Mon Sep 17 00:00:00 2001 From: Martin Biel Date: Tue, 15 Aug 2017 18:03:57 +0200 Subject: [PATCH 14/68] Process user recipes depth-first rather than breadth-first to enforce the plot order given in the recipe --- src/pipeline.jl | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/pipeline.jl b/src/pipeline.jl index 83eff845..231caa45 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -60,29 +60,26 @@ function _process_userrecipes(plt::Plot, d::KW, args) args = _preprocess_args(d, args, still_to_process) # for plotting recipes, swap out the args and update the parameter dictionary - # we are keeping a queue of series that still need to be processed. + # we are keeping a stack of series that still need to be processed. # each pass through the loop, we pop one off and apply the recipe. # the recipe will return a list a Series objects... the ones that are - # finished (no more args) get added to the kw_list, and the rest go into the queue - # for processing. + # finished (no more args) get added to the kw_list, the ones that are not + # are placed on top of the stack and are then processed further. kw_list = KW[] while !isempty(still_to_process) - # grab the first in line to be processed and pass it through apply_recipe - # to generate a list of RecipeData objects (data + attributes) + # grab the first in line to be processed and either add it to the kw_list or + # pass it through apply_recipe to generate a list of RecipeData objects (data + attributes) + # for further processing. next_series = shift!(still_to_process) - rd_list = RecipesBase.apply_recipe(next_series.d, next_series.args...) - for recipedata in rd_list - # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes - if !(typeof(recipedata) <: RecipeData) - error("Inputs couldn't be processed... expected RecipeData but got: $recipedata") - end - - if isempty(recipedata.args) - _process_userrecipe(plt, kw_list, recipedata) - else - # args are non-empty, so there's still processing to do... add it back to the queue - push!(still_to_process, recipedata) - end + # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes + if !(typeof(next_series) <: RecipeData) + error("Inputs couldn't be processed... expected RecipeData but got: $recipedata") + end + if isempty(next_series.args) + _process_userrecipe(plt, kw_list, next_series) + else + rd_list = RecipesBase.apply_recipe(next_series.d, next_series.args...) + prepend!(still_to_process,rd_list) end end From a1d0d028b6e4a38917a8b6f2200696daba2d7646 Mon Sep 17 00:00:00 2001 From: Martin Biel Date: Wed, 16 Aug 2017 10:16:37 +0200 Subject: [PATCH 15/68] Updated error text in _process_userrecipes, now uses correct variable --- src/pipeline.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline.jl b/src/pipeline.jl index 231caa45..8879ff6f 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -73,7 +73,7 @@ function _process_userrecipes(plt::Plot, d::KW, args) next_series = shift!(still_to_process) # recipedata should be of type RecipeData. if it's not then the inputs must not have been fully processed by recipes if !(typeof(next_series) <: RecipeData) - error("Inputs couldn't be processed... expected RecipeData but got: $recipedata") + error("Inputs couldn't be processed... expected RecipeData but got: $next_series") end if isempty(next_series.args) _process_userrecipe(plt, kw_list, next_series) From e0c679f5ee820754bb1664098afca5c959e9892f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 16 Aug 2017 17:45:32 +0200 Subject: [PATCH 16/68] magic grid argument --- src/Plots.jl | 4 +-- src/arg_desc.jl | 8 +++-- src/args.jl | 70 +++++++++++++++++++++++++++++++++++++ src/axes.jl | 4 +-- src/backends/glvisualize.jl | 11 +++--- src/backends/gr.jl | 27 ++++++-------- src/backends/inspectdr.jl | 4 +-- src/backends/pgfplots.jl | 2 +- src/backends/plotly.jl | 13 ++++--- src/backends/pyplot.jl | 11 ++++-- src/examples.jl | 12 +++++++ 11 files changed, 127 insertions(+), 39 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index d320df7c..2e504051 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -215,8 +215,8 @@ xflip!(flip::Bool = true; kw...) = plot!(; xflip = flip yflip!(flip::Bool = true; kw...) = plot!(; yflip = flip, kw...) xaxis!(args...; kw...) = plot!(; xaxis = args, kw...) yaxis!(args...; kw...) = plot!(; yaxis = args, kw...) -xgrid!(grid::Bool = true; kw...) = plot!(; xgrid = grid, kw...) -ygrid!(grid::Bool = true; kw...) = plot!(; ygrid = grid, kw...) +xgrid!(args...; kw...) = plot!(; xgrid = args, kw...) +ygrid!(args...; kw...) = plot!(; ygrid = args, kw...) let PlotOrSubplot = Union{Plot, Subplot} title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 571400a7..ee1e99d8 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -76,7 +76,6 @@ const _arg_desc = KW( :background_color_inside => "Color Type or `:match` (matches `:background_color_subplot`). Background color inside the plot area (under the grid).", :foreground_color_subplot => "Color Type or `:match` (matches `:foreground_color`). Base foreground color of the subplot.", :foreground_color_legend => "Color Type or `:match` (matches `:foreground_color_subplot`). Foreground color of the legend.", -:foreground_color_grid => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of grid lines.", :foreground_color_title => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of subplot title.", :color_palette => "Vector of colors (cycle through) or color gradient (generate list from gradient) or `:auto` (generate a color list using `Colors.distiguishable_colors` and custom seed colors chosen to contrast with the background). The color palette is a color list from which series colors are automatically chosen.", :legend => "Bool (show the legend?) or Symbol (legend position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:inside`, `:legend`, `:topright`, `:topleft`, `:bottomleft`, `:bottomright` (note: only some may be supported in each backend)", @@ -110,6 +109,9 @@ const _arg_desc = KW( :foreground_color_text => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of tick labels.", :foreground_color_guide => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of axis guides (axis labels).", :mirror => "Bool. Switch the side of the tick labels (right or top).", -:grid => "Bool. Show the grid lines?", - +:grid => "Bool, Symbol, String or `nothing`. Show the grid lines? `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:none`, `:off`", +:foreground_color_grid => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of grid lines.", +:gridalpha => "Number in [0,1]. The alpha/opacity override for the grid lines.", +:gridstyle => "Symbol. Style of the grid lines. Choose from $(_allStyles)", +:gridlinewidth => "Number. Width of the grid lines (in pixels)", ) diff --git a/src/args.jl b/src/args.jl index 0012bc7e..01cafb51 100644 --- a/src/args.jl +++ b/src/args.jl @@ -163,6 +163,24 @@ const _scaleAliases = Dict{Symbol,Symbol}( :log => :log10, ) +const _allGridSyms = [:x, :y, :z, + :xy, :xz, :yx, :yz, :zx, :zy, + :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, + :all, :both, :on, + :none, :off,] +const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing; false; true] +hasgrid(arg::Void, letter) = false +hasgrid(arg::Bool, letter) = arg +function hasgrid(arg::Symbol, letter) + if arg in _allGridSyms + arg in (:all, :both, :on) || contains(string(arg), string(letter)) + else + warn("Unknown grid argument $arg; $letter\grid was set to `true` instead") + true + end +end +hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter) + # ----------------------------------------------------------------------------- const _series_defaults = KW( @@ -285,6 +303,9 @@ const _axis_defaults = KW( :mirror => false, :grid => true, :foreground_color_grid => :match, # grid color + :gridalpha => 0.3, + :gridstyle => :dot, + :gridlinewidth => 1, ) const _suppress_warnings = Set{Symbol}([ @@ -414,6 +435,7 @@ 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) +add_aliases(:gridalpha, :ga, :galpha, :gα, :gridopacity, :gopacity) # series attributes add_aliases(:seriestype, :st, :t, :typ, :linetype, :lt) @@ -469,6 +491,8 @@ add_aliases(:series_annotations, :series_ann, :seriesann, :series_anns, :seriesa add_aliases(:html_output_format, :format, :fmt, :html_format) add_aliases(:orientation, :direction, :dir) add_aliases(:inset_subplots, :inset, :floating) +add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) +add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) # add all pluralized forms to the _keyAliases dict @@ -645,6 +669,36 @@ function processFillArg(d::KW, arg) return end + +function processGridArg!(d::KW, arg, letter) + if arg in _allGridArgs + d[Symbol(letter, :grid)] = hasgrid(arg, letter) + + elseif allStyles(arg) + d[Symbol(letter, :gridstyle)] = arg + + elseif typeof(arg) <: Stroke + arg.width == nothing || (d[Symbol(letter, :gridlinewidth)] = arg.width) + arg.color == nothing || (d[Symbol(letter, :foreground_color_grid)] = arg.color in (:auto, :match) ? :match : plot_color(arg.color)) + arg.alpha == nothing || (d[Symbol(letter, :gridalpha)] = arg.alpha) + arg.style == nothing || (d[Symbol(letter, :gridstyle)] = arg.style) + + # linealpha + elseif allAlphas(arg) + d[Symbol(letter, :gridalpha)] = arg + + # linewidth + elseif allReals(arg) + d[Symbol(letter, :gridlinewidth)] = arg + + # color +elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_grid)) + warn("Skipped grid arg $arg.") + + end +end + + _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape) _replace_markershape(shapes::AVec) = map(_replace_markershape, shapes) _replace_markershape(shape) = shape @@ -688,6 +742,22 @@ function preprocessArgs!(d::KW) end end + # handle grid args common to all axes + args = pop!(d, :grid, ()) + for arg in wraptuple(args) + for letter in (:x, :y, :z) + processGridArg!(d, arg, letter) + end + end + # handle individual axes grid args + for letter in (:x, :y, :z) + gridsym = Symbol(letter, :grid) + args = pop!(d, gridsym, ()) + for arg in wraptuple(args) + processGridArg!(d, arg, letter) + end + end + # handle line args for arg in wraptuple(pop!(d, :line, ())) processLineArg(d, arg) diff --git a/src/axes.jl b/src/axes.jl index cafee577..734f2154 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -506,7 +506,7 @@ function axis_drawing_info(sp::Subplot) for xtick in xticks[1] push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick # push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick - !(xaxis[:grid] in (nothing, false)) && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid + xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid end end @@ -521,7 +521,7 @@ function axis_drawing_info(sp::Subplot) for ytick in yticks[1] push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick # push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick - !(yaxis[:grid] in (nothing, false)) && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid end end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 118db197..60c1730a 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -24,7 +24,8 @@ const _glvisualize_attr = merge_with_base_supported([ :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, :tickfont, :guidefont, :legendfont, - :grid, :legend, :colorbar, + :grid, :gridalpha, :gridstyle, :gridlinewidth, + :legend, :colorbar, :marker_z, :line_z, :levels, @@ -682,12 +683,12 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid])) ygc = Colors.color(Plots.gl_color(yaxis[:foreground_color_grid])) axis_vis = [] - if !(xaxis[:grid] in (nothing, false)) - grid = draw_grid_lines(sp, xgrid_segs, 1f0, :dot, model, RGBA(xgc, 0.3f0)) + if xaxis[:grid] + grid = draw_grid_lines(sp, xgrid_segs, xaxis[:gridlinewidth], xaxis[:gridstyle], model, RGBA(xgc, xaxis[:gridalpha])) push!(axis_vis, grid) end - if !(yaxis[:grid] in (nothing, false)) - grid = draw_grid_lines(sp, ygrid_segs, 1f0, :dot, model, RGBA(ygc, 0.3f0)) + if yaxis[:grid] + grid = draw_grid_lines(sp, ygrid_segs, yaxis[:gridlinewidth], yaxis[:gridstyle], model, RGBA(ygc, yaxis[:gridalpha])) push!(axis_vis, grid) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index a0a9171d..061dee7f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -20,7 +20,8 @@ const _gr_attr = merge_with_base_supported([ :title, :window_title, :guide, :lims, :ticks, :scale, :flip, :tickfont, :guidefont, :legendfont, - :grid, :legend, :legendtitle, :colorbar, + :grid, :gridalpha, :gridstyle, :gridlinewidth, + :legend, :legendtitle, :colorbar, :marker_z, :levels, :ribbon, :quiver, :orientation, @@ -691,15 +692,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) ticksize = 0.01 * (viewport_plotarea[2] - viewport_plotarea[1]) # GR.setlinetype(GR.LINETYPE_DOTTED) - if !(xaxis[:grid] in (nothing, false)) - GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0) - end - if !(yaxis[:grid] in (nothing, false)) - GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) - end - if !(zaxis[:grid] in (nothing, false)) - GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2) - end + xaxis[:grid] && GR.grid3d(xtick, 0, 0, xmin, ymax, zmin, 2, 0, 0) + yaxis[:grid] && GR.grid3d(0, ytick, 0, xmin, ymax, zmin, 0, 2, 0) + zaxis[:grid] && GR.grid3d(0, 0, ztick, xmin, ymax, zmin, 0, 0, 2) GR.axes3d(xtick, 0, ztick, xmin, ymin, zmin, 2, 0, 2, -ticksize) GR.axes3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0, ticksize) @@ -718,16 +713,16 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # @show xticks yticks #spine_segs grid_segs # draw the grid lines - if !(xaxis[:grid] in (nothing, false)) + if xaxis[:grid] # gr_set_linecolor(sp[:foreground_color_grid]) # GR.grid(xtick, ytick, 0, 0, majorx, majory) - gr_set_line(1, :dot, xaxis[:foreground_color_grid]) - GR.settransparency(0.5) + gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid]) + GR.settransparency(xaxis[:gridalpha]) gr_polyline(coords(xgrid_segs)...) end - if !(yaxis[:grid] in (nothing, false)) - gr_set_line(1, :dot, yaxis[:foreground_color_grid]) - GR.settransparency(0.5) + if yaxis[:grid] + gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid]) + GR.settransparency(yaxis[:gridalpha]) gr_polyline(coords(ygrid_segs)...) end GR.settransparency(1.0) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 1feda4ba..a8224634 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -339,8 +339,8 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) const strip = plot.strips[1] #Only 1 strip supported with Plots.jl xaxis = sp[:xaxis]; yaxis = sp[:yaxis] - xgrid_show = !(xaxis[:grid] in (nothing, false)) - ygrid_show = !(yaxis[:grid] in (nothing, false)) + xgrid_show = xaxis[:grid] + ygrid_show = yaxis[:grid] strip.grid = InspectDR.GridRect( vmajor=xgrid_show, # vminor=xgrid_show, diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index cbbd645b..30169147 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -267,7 +267,7 @@ function pgf_axis(sp::Subplot, letter) end # grid on or off - if !(axis[:grid] in (nothing, false)) + if axis[:grid] push!(style, "$(letter)majorgrids = true") end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index cc0aed9c..9e0537ce 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -5,7 +5,7 @@ const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, :foreground_color_legend, :foreground_color_guide, - # :foreground_color_grid, :foreground_color_axis, + :foreground_color_grid, :foreground_color_axis, :foreground_color_text, :foreground_color_border, :foreground_color_title, :label, @@ -19,7 +19,8 @@ const _plotly_attr = merge_with_base_supported([ :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, :tickfont, :guidefont, :legendfont, - :grid, :legend, :colorbar, :colorbar_title, + :grid, :gridalpha, :gridlinewidth, + :legend, :colorbar, :colorbar_title, :marker_z, :fill_z, :levels, :ribbon, :quiver, :orientation, @@ -213,7 +214,9 @@ function plotly_axis(axis::Axis, sp::Subplot) letter = axis[:letter] ax = KW( :title => axis[:guide], - :showgrid => !(axis[:grid] in (nothing, false)), + :showgrid => axis[:grid], + :gridcolor => rgba_string(plot_color(axis[:foreground_color_grid], axis[:gridalpha])), + :gridwidth => axis[:gridlinewidth], :zeroline => false, :ticks => "inside", ) @@ -229,8 +232,8 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) - ax[:tickcolor] = rgba_string(axis[:foreground_color_border]) - ax[:linecolor] = rgba_string(axis[:foreground_color_border]) + ax[:tickcolor] = rgba_string(axis[:foreground_color_axis]) + ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) # lims lims = axis[:lims] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 4100ccbf..4b185e6e 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -17,7 +17,8 @@ const _pyplot_attr = merge_with_base_supported([ :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, :tickfont, :guidefont, :legendfont, - :grid, :legend, :legendtitle, :colorbar, + :grid, :gridalpha, :gridstyle, :gridlinewidth, + :legend, :legendtitle, :colorbar, :marker_z, :line_z, :fill_z, :levels, :ribbon, :quiver, :arrow, @@ -1064,9 +1065,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) lab[:set_family](axis[:tickfont].family) lab[:set_rotation](axis[:rotation]) end - if !(axis[:grid] in (nothing, false)) + if axis[:grid] fgcolor = py_color(axis[:foreground_color_grid]) - pyaxis[:grid](true, color = fgcolor, linestyle = ":") + pyaxis[:grid](true, + color = fgcolor, + linestyle = py_linestyle(:line, axis[:gridstyle]), + linewidth = axis[:gridlinewidth], + alpha = axis[:gridalpha]) ax[:set_axisbelow](true) end py_set_axis_colors(ax, axis) diff --git a/src/examples.jl b/src/examples.jl index a9b86960..640dde92 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -329,6 +329,18 @@ PlotExample("Spy", end)] ), +PlotExample("Magic grid argument", + "The grid lines can be modified individually for each axis with the magic grid argument", + [:(begin + x = rand(10) + p1 = plot(x, title = "Default looks") + p2 = plot(x, grid = (:y, :olivedrab, :solid, 0.5), title = "Modified y grid") + p3 = plot(deepcopy(p2), title = "Add x grid") + xgrid!(p3, :on, :cadetblue, 2, :dashdot) + plot(p1, p2, p3, layout = (1, 3), label = "", fillrange = 0, fillalpha = 0.3) + end)] +), + ] # --------------------------------------------------------------------------------- From 682ba1f7640ce007540f921f4de345f39de29111 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 16 Aug 2017 19:41:13 +0200 Subject: [PATCH 17/68] allow non-boolean args for xgrid function --- src/Plots.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 2e504051..32340a10 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -234,8 +234,8 @@ let PlotOrSubplot = Union{Plot, Subplot} ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; xticks = (ticks,labels), kw...) yticks!{T<:Real,S<:AbstractString}(plt::PlotOrSubplot, ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(plt; yticks = (ticks,labels), kw...) - xgrid!(plt::PlotOrSubplot, grid::Bool = true; kw...) = plot!(plt; xgrid = grid, kw...) - ygrid!(plt::PlotOrSubplot, grid::Bool = true; kw...) = plot!(plt; ygrid = grid, kw...) + xgrid!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; xgrid = args, kw...) + ygrid!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; ygrid = args, kw...) annotate!(plt::PlotOrSubplot, anns...; kw...) = plot!(plt; annotation = anns, kw...) annotate!{T<:Tuple}(plt::PlotOrSubplot, anns::AVec{T}; kw...) = plot!(plt; annotation = anns, kw...) xflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; xflip = flip, kw...) From bb2f4ff16b97f44c2dae7f6204b694ce7cd122d6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 16 Aug 2017 21:05:05 +0200 Subject: [PATCH 18/68] import inplace plot placeholder from RecipesBase --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index e7c7fc66..4f104ea6 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -8,7 +8,7 @@ import StaticArrays using StaticArrays.FixedSizeArrays @reexport using RecipesBase -import RecipesBase: plot, animate +import RecipesBase: plot, plot!, animate using Base.Meta @reexport using PlotUtils @reexport using PlotThemes From 8288e85c2567788301d9c6e79fb802333695e86e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 16 Aug 2017 22:32:00 +0200 Subject: [PATCH 19/68] only flip colorbar for marker_z --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 80b52822..4716aa8e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -336,6 +336,7 @@ function gr_draw_markers(series::Series, x, y) GR.setfillintstyle(GR.INTSTYLE_SOLID) gr_draw_markers(series, x, y, series[:markersize], mz) if mz != nothing + GR.setscale(0) gr_colorbar(series[:subplot]) end end @@ -863,7 +864,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if series[:marker_z] != nothing zmin, zmax = extrema(series[:marker_z]) GR.setspace(zmin, zmax, 0, 90) - GR.setscale(0) end gr_draw_markers(series, x, y) end From 4b60b05f757b274cf2a037c5ca8f1fe14dc05bbe Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 17 Aug 2017 13:42:54 +0200 Subject: [PATCH 20/68] update grid defaults and modify grid example --- src/args.jl | 8 ++++---- src/examples.jl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/args.jl b/src/args.jl index 01cafb51..e68e6be6 100644 --- a/src/args.jl +++ b/src/args.jl @@ -175,7 +175,7 @@ function hasgrid(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on) || contains(string(arg), string(letter)) else - warn("Unknown grid argument $arg; $letter\grid was set to `true` instead") + warn("Unknown grid argument $arg; $letter\grid was set to `true` instead.") true end end @@ -303,9 +303,9 @@ const _axis_defaults = KW( :mirror => false, :grid => true, :foreground_color_grid => :match, # grid color - :gridalpha => 0.3, - :gridstyle => :dot, - :gridlinewidth => 1, + :gridalpha => 0.1, + :gridstyle => :solid, + :gridlinewidth => 0.5, ) const _suppress_warnings = Set{Symbol}([ diff --git a/src/examples.jl b/src/examples.jl index 640dde92..87ae1ca4 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -321,7 +321,7 @@ PlotExample("Animation with subplots", ), PlotExample("Spy", - "For a matrix `mat` with unique nonzeros `spy(mat)` returns a colorless plot. If `mat` has various different nonzero values, a colorbar is added. The colorbar can be disabled with `legend = nothing`. As always, the marker shape and size can be changed with `spy(mat, markersize = 3, markershape = :star)`", + "For a matrix `mat` with unique nonzeros `spy(mat)` returns a colorless plot. If `mat` has various different nonzero values, a colorbar is added. The colorbar can be disabled with `legend = nothing`. As always, the marker shape and size can be changed with `spy(mat, markersize = 3, markershape = :star)`.", [:(begin a = spdiagm((ones(50), ones(49), ones(49), ones(40), ones(40)),(0, 1, -1, 10, -10)) b = spdiagm((1:50, 1:49, 1:49, 1:40, 1:40),(0, 1, -1, 10, -10)) @@ -330,13 +330,13 @@ PlotExample("Spy", ), PlotExample("Magic grid argument", - "The grid lines can be modified individually for each axis with the magic grid argument", + "The grid lines can be modified individually for each axis with the magic grid argument.", [:(begin x = rand(10) p1 = plot(x, title = "Default looks") - p2 = plot(x, grid = (:y, :olivedrab, :solid, 0.5), title = "Modified y grid") + p2 = plot(x, grid = (:y, :olivedrab, :dot, 1, 0.9), title = "Modified y grid") p3 = plot(deepcopy(p2), title = "Add x grid") - xgrid!(p3, :on, :cadetblue, 2, :dashdot) + xgrid!(p3, :on, :cadetblue, 2, :dashdot, 0.4) plot(p1, p2, p3, layout = (1, 3), label = "", fillrange = 0, fillalpha = 0.3) end)] ), From 42f54b8df949d49dca9664989ea56bc658f323a5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 17 Aug 2017 14:10:04 +0200 Subject: [PATCH 21/68] remove Bools from _allGridArgs --- src/args.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/args.jl b/src/args.jl index e68e6be6..d861fea3 100644 --- a/src/args.jl +++ b/src/args.jl @@ -168,7 +168,7 @@ const _allGridSyms = [:x, :y, :z, :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, :all, :both, :on, :none, :off,] -const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing; false; true] +const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] hasgrid(arg::Void, letter) = false hasgrid(arg::Bool, letter) = arg function hasgrid(arg::Symbol, letter) @@ -671,7 +671,7 @@ end function processGridArg!(d::KW, arg, letter) - if arg in _allGridArgs + if arg in _allGridArgs || isa(arg, Bool) d[Symbol(letter, :grid)] = hasgrid(arg, letter) elseif allStyles(arg) From 4be0093a8a41bd1136c2388e9596810be91c6e9f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 18 Aug 2017 00:34:15 +0200 Subject: [PATCH 22/68] prepare release --- NEWS.md | 13 +++++++++++-- src/Plots.jl | 2 +- test/imgcomp.jl | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8113ae7b..8a7e19d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,14 +11,23 @@ --- ## (current master) -## 0.12.2 +## 0.12.3 + +- new grid line style defaults +- `grid` is now an axis attribute and a magic argument: it is now possible to modify the grid line style, alpha and line width +- Enforce plot order in user recipes +- import `plot!` from RecipesBase +- GR no longer automatically handles _ and ^ in texts +- fix GR colorbar for scatter plots + +#### 0.12.2 - fix an issue with Juno/PlotlyJS compatibility on new installations - fix markers not showing up in seriesrecipes using :scatter - don't use pywrap in the pyplot backend - improve the bottom margin for the gr backend -## 0.12.1 +#### 0.12.1 - fix deprecation warnings - switch from FixedSizeArrays to StaticArrays.FixedSizeArrays diff --git a/src/Plots.jl b/src/Plots.jl index e7c7fc66..625dba5e 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(true) +__precompile__(false) module Plots diff --git a/test/imgcomp.jl b/test/imgcomp.jl index 7d6ae303..f3c0ee22 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -23,7 +23,7 @@ default(size=(500,300)) # TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that # is referenced in a button press callback (the button clicked callback will call notify() on that condition) -const _current_plots_version = v"0.12.1" +const _current_plots_version = v"0.12.3" function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2) From 4c1c0922346c08708c595e02fa99c248f007bb08 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 18 Aug 2017 00:46:02 +0200 Subject: [PATCH 23/68] reactivate precompilation --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 625dba5e..e7c7fc66 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(false) +__precompile__(true) module Plots From 66ce38d94851eb83622be9975c5af426dd0e57ae Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 15 Aug 2017 23:02:31 +0200 Subject: [PATCH 24/68] Specified some docstrings --- src/Plots.jl | 32 +++++++++++++++++++++++++++++++- src/args.jl | 1 - src/backends.jl | 3 +++ src/components.jl | 12 ++++++++++++ src/layouts.jl | 12 ++++++++++++ src/output.jl | 12 ++++++++++++ src/plot.jl | 4 ++++ src/subplots.jl | 5 +++++ src/themes.jl | 4 ++++ src/utils.jl | 21 ++++++++++++++++++++- 10 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index bca0d9c9..c75a8e65 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -188,32 +188,62 @@ include("output.jl") @shorthands quiver @shorthands curves +"Plot a pie diagram" pie(args...; kw...) = plot(args...; kw..., seriestype = :pie, aspect_ratio = :equal, grid=false, xticks=nothing, yticks=nothing) pie!(args...; kw...) = plot!(args...; kw..., seriestype = :pie, aspect_ratio = :equal, grid=false, xticks=nothing, yticks=nothing) + +"Plot with seriestype :path3d" plot3d(args...; kw...) = plot(args...; kw..., seriestype = :path3d) plot3d!(args...; kw...) = plot!(args...; kw..., seriestype = :path3d) - +"Add title to an existing plot" title!(s::AbstractString; kw...) = plot!(; title = s, kw...) + +"Add xlabel to an existing plot" xlabel!(s::AbstractString; kw...) = plot!(; xlabel = s, kw...) + +"Add ylabel to an existing plot" ylabel!(s::AbstractString; kw...) = plot!(; ylabel = s, kw...) + +"Set xlims for an existing plot" xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; xlims = lims, kw...) + +"Set ylims for an existing plot" ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; ylims = lims, kw...) + +"Set zlims for an existing plot" zlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; zlims = lims, kw...) + xlims!(xmin::Real, xmax::Real; kw...) = plot!(; xlims = (xmin,xmax), kw...) ylims!(ymin::Real, ymax::Real; kw...) = plot!(; ylims = (ymin,ymax), kw...) zlims!(zmin::Real, zmax::Real; kw...) = plot!(; zlims = (zmin,zmax), kw...) + + +"Set xticks for an existing plot" xticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; xticks = v, kw...) + +"Set yticks for an existing plot" yticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; yticks = v, kw...) + xticks!{T<:Real,S<:AbstractString}( ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; xticks = (ticks,labels), kw...) yticks!{T<:Real,S<:AbstractString}( ticks::AVec{T}, labels::AVec{S}; kw...) = plot!(; yticks = (ticks,labels), kw...) + +"Add annotations to an existing plot" annotate!(anns...; kw...) = plot!(; annotation = anns, kw...) annotate!{T<:Tuple}(anns::AVec{T}; kw...) = plot!(; annotation = anns, kw...) + +"Flip the current plots' x axis" xflip!(flip::Bool = true; kw...) = plot!(; xflip = flip, kw...) + +"Flip the current plots' y axis" yflip!(flip::Bool = true; kw...) = plot!(; yflip = flip, kw...) + +"Specify x axis attributes for an existing plot" xaxis!(args...; kw...) = plot!(; xaxis = args, kw...) + +"Specify x axis attributes for an existing plot" yaxis!(args...; kw...) = plot!(; yaxis = args, kw...) xgrid!(args...; kw...) = plot!(; xgrid = args, kw...) ygrid!(args...; kw...) = plot!(; ygrid = args, kw...) diff --git a/src/args.jl b/src/args.jl index d861fea3..37dd250e 100644 --- a/src/args.jl +++ b/src/args.jl @@ -512,7 +512,6 @@ end `default(; kw...)` will set the current default value for each key/value pair `default(d, key)` returns the key from d if it exists, otherwise `default(key)` """ - function default(k::Symbol) k = get(_keyAliases, k, k) for defaults in _all_defaults diff --git a/src/backends.jl b/src/backends.jl index 19a9c6ea..b445807c 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -6,7 +6,10 @@ const _backendSymbol = Dict{DataType, Symbol}(NoBackend => :none) const _backends = Symbol[] const _initialized_backends = Set{Symbol}() +"Returns a list of supported backends" backends() = _backends + +"Returns the name of the current backend" backend_name() = CURRENT_BACKEND.sym _backend_instance(sym::Symbol) = haskey(_backendType, sym) ? _backendType[sym]() : error("Unsupported backend $sym") diff --git a/src/components.jl b/src/components.jl index 2962f184..0ffe6226 100644 --- a/src/components.jl +++ b/src/components.jl @@ -22,6 +22,13 @@ immutable Shape # end # end end + +""" + Shape(x, y) + Shape(vertices) + +Construct a polygon to be plotted +""" Shape(verts::AVec) = Shape(unzip(verts)...) Shape(s::Shape) = deepcopy(s) @@ -331,6 +338,11 @@ immutable PlotText end PlotText(str) = PlotText(string(str), font()) +""" + text(string, args...) + +Create a PlotText object wrapping a string with font info, for plot annotations +""" text(t::PlotText) = t text(str::AbstractString, f::Font) = PlotText(str, f) function text(str, args...) diff --git a/src/layouts.jl b/src/layouts.jl index 71f8b7a1..9e90a2f1 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -133,7 +133,12 @@ make_measure_hor(m::Measure) = m make_measure_vert(n::Number) = n * h make_measure_vert(m::Measure) = m +""" + bbox(x, y, w, h [,originargs...]) + bbox(layout) +Create a bounding box for plotting +""" function bbox(x, y, w, h, oarg1::Symbol, originargs::Symbol...) oargs = vcat(oarg1, originargs...) orighor = :left @@ -253,6 +258,13 @@ type GridLayout <: AbstractLayout attr::KW end +""" + grid(args...; kw...) + +Create a grid layout for subplots. `args` specify the dimensions, e.g. +`grid(3,2, widths = (0.6,04))` creates a grid with three rows and two +columns of different width. +""" grid(args...; kw...) = GridLayout(args...; kw...) function GridLayout(dims...; diff --git a/src/output.jl b/src/output.jl index 5c036fe7..14f15c30 100644 --- a/src/output.jl +++ b/src/output.jl @@ -97,6 +97,13 @@ function addExtension(fn::AbstractString, ext::AbstractString) end end +""" + savefig([plot,] filename) + +Save a Plot (the current plot if `plot` is not passed) to file. The file +type is inferred from the file extension. All backends support png and pdf +file types, some also support svg, ps, eps, html and tex. +""" function savefig(plt::Plot, fn::AbstractString) # get the extension @@ -119,7 +126,11 @@ savefig(fn::AbstractString) = savefig(current(), fn) # --------------------------------------------------------- +""" + gui([plot]) +Display a plot using the backends' gui window +""" gui(plt::Plot = current()) = display(PlotsDisplay(), plt) # IJulia only... inline display @@ -198,6 +209,7 @@ for mime in keys(_mimeformats) end end +"Close all open gui windows of the current backend" closeall() = closeall(backend()) diff --git a/src/plot.jl b/src/plot.jl index 3ab41701..3e6dd9a3 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -6,6 +6,10 @@ const CURRENT_PLOT = CurrentPlot(Nullable{AbstractPlot}()) isplotnull() = isnull(CURRENT_PLOT.nullableplot) +""" + current() +Returns the Plot object for the current plot +""" function current() if isplotnull() error("No current plot/subplot") diff --git a/src/subplots.jl b/src/subplots.jl index ccd1478c..5629125f 100644 --- a/src/subplots.jl +++ b/src/subplots.jl @@ -13,6 +13,11 @@ function Subplot{T<:AbstractBackend}(::T; parent = RootLayout()) ) end +""" + plotarea(subplot) + +Return the bounding box of a subplot +""" plotarea(sp::Subplot) = sp.plotarea plotarea!(sp::Subplot, bbox::BoundingBox) = (sp.plotarea = bbox) diff --git a/src/themes.jl b/src/themes.jl index e7a39d02..840078dd 100644 --- a/src/themes.jl +++ b/src/themes.jl @@ -1,4 +1,8 @@ +""" + theme(s::Symbol) +Specify the colour theme for plots. +""" function theme(s::Symbol; kw...) # reset? if s == :none || s == :default diff --git a/src/utils.jl b/src/utils.jl index d8aced3d..6add802a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -500,9 +500,28 @@ end function get_sp_lims(sp::Subplot, letter::Symbol) axis_limits(sp[Symbol(letter, :axis)]) end + +""" + xlims([plt]) + +Returns the x axis limits of the current plot or subplot +""" xlims(sp::Subplot) = get_sp_lims(sp, :x) + +""" + ylims([plt]) + +Returns the y axis limits of the current plot or subplot +""" ylims(sp::Subplot) = get_sp_lims(sp, :y) + +""" + zlims([plt]) + +Returns the z axis limits of the current plot or subplot +""" zlims(sp::Subplot) = get_sp_lims(sp, :z) + xlims(plt::Plot, sp_idx::Int = 1) = xlims(plt[sp_idx]) ylims(plt::Plot, sp_idx::Int = 1) = ylims(plt[sp_idx]) zlims(plt::Plot, sp_idx::Int = 1) = zlims(plt[sp_idx]) @@ -536,7 +555,7 @@ allFunctions(arg) = trueOrAllTrue(a -> isa(a, Function), arg) """ Allows temporary setting of backend and defaults for Plots. Settings apply only for the `do` block. Example: ``` -with(:gadfly, size=(400,400), type=:histogram) do +with(:gr, size=(400,400), type=:histogram) do plot(rand(10)) plot(rand(10)) end From db82f223204851b50a6718a0cb7bb184b3a28b22 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 16 Aug 2017 11:21:44 +0200 Subject: [PATCH 25/68] add the last docstrings --- src/animation.jl | 9 +++++++-- src/components.jl | 17 ++++++++++++++++- src/examples.jl | 7 +++++++ src/plotattr.jl | 6 ++++++ src/recipes.jl | 1 + src/utils.jl | 3 ++- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 55a9fe53..4afa01cf 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -1,4 +1,4 @@ - +"Represents an animation object" immutable Animation dir::String frames::Vector{String} @@ -9,6 +9,11 @@ function Animation() Animation(tmpdir, String[]) end +""" + frame(animation[, plot]) + +Add a plot (the current plot if not specified) to an existing animation +""" function frame{P<:AbstractPlot}(anim::Animation, plt::P=current()) i = length(anim.frames) + 1 filename = @sprintf("%06d.png", i) @@ -81,7 +86,7 @@ function buildanimation(animdir::AbstractString, fn::AbstractString; catch err warn("""Tried to create gif using convert (ImageMagick), but got error: $err ImageMagick can be installed by executing `Pkg.add("ImageMagick")`. - You may also need to install the imagemagick c++ library through your operating system. + You may also need to install the imagemagick c++ library through your operating system. Will try ffmpeg, but it's lower quality...)""") # low quality diff --git a/src/components.jl b/src/components.jl index 0ffe6226..eba135c2 100644 --- a/src/components.jl +++ b/src/components.jl @@ -39,6 +39,7 @@ vertices(shape::Shape) = collect(zip(shape.x, shape.y)) #deprecated @deprecate shape_coords coords +"return the vertex points from a Shape or Segments object" function coords(shape::Shape) shape.x, shape.y end @@ -163,6 +164,7 @@ Shape(k::Symbol) = deepcopy(_shapes[k]) # uses the centroid calculation from https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon +"return the centroid of a Shape" function center(shape::Shape) x, y = coords(shape) n = length(x) @@ -196,6 +198,7 @@ function scale(shape::Shape, x::Real, y::Real = x, c = center(shape)) scale!(shapecopy, x, y, c) end +"translate a Shape in space" function translate!(shape::Shape, x::Real, y::Real = x) sx, sy = coords(shape) for i=1:length(sx) @@ -234,6 +237,7 @@ function rotate!(shape::Shape, Θ::Real, c = center(shape)) shape end +"rotate an object in space" function rotate(shape::Shape, Θ::Real, c = center(shape)) shapecopy = deepcopy(shape) rotate!(shapecopy, Θ, c) @@ -362,6 +366,11 @@ immutable Stroke style end +""" + stroke(args...; alpha = nothing) + +Define the properties of the stroke used in plotting lines +""" function stroke(args...; alpha = nothing) width = 1 color = :black @@ -609,6 +618,12 @@ immutable Arrow headwidth::Float64 end +""" + arrow(args...) + +Define arrowheads to apply to lines - args are `style` (`:open` or `:closed`), +`side` (`:head`, `:tail` or `:both`), `headlength` and `headwidth` +""" function arrow(args...) style = :simple side = :head @@ -664,7 +679,7 @@ immutable Formatted{T} end # ----------------------------------------------------------------------- - +"create a BezierCurve for plotting" type BezierCurve{T <: FixedSizeArrays.Vec} control_points::Vector{T} end diff --git a/src/examples.jl b/src/examples.jl index 87ae1ca4..8ae108ef 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -360,6 +360,13 @@ function test_examples(pkgname::Symbol, idx::Int; debug = false, disp = true) end # generate all plots and create a dict mapping idx --> plt +""" +test_examples(pkgname[, idx]; debug = false, disp = true, sleep = nothing, + skip = [], only = nothing + +Run the `idx` test example for a given backend, or all examples if `idx` +is not specified. +""" function test_examples(pkgname::Symbol; debug = false, disp = true, sleep = nothing, skip = [], only = nothing) Plots._debugMode.on = debug diff --git a/src/plotattr.jl b/src/plotattr.jl index cc8d053b..7313b2ce 100644 --- a/src/plotattr.jl +++ b/src/plotattr.jl @@ -14,6 +14,12 @@ function lookup_aliases(attrtype, attribute) error("There is no attribute named $attribute in $attrtype") end +""" + plotattr([attr]) + +Look up the properties of a Plots attribute, or specify an attribute type. Call `plotattr()` for options. +The information is the same as that given on https://juliaplots.github.io/attributes/. +""" function plotattr() println("Specify an attribute type to get a list of supported attributes. Options are $(attrtypes())") end diff --git a/src/recipes.jl b/src/recipes.jl index f5cb9b73..393bc2d4 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -847,6 +847,7 @@ end # TODO: move OHLC to PlotRecipes finance.jl +"Represent Open High Low Close data (used in finance)" type OHLC{T<:Real} open::T high::T diff --git a/src/utils.jl b/src/utils.jl index 6add802a..7e67f877 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -137,7 +137,7 @@ function imageHack(d::KW) end # --------------------------------------------------------------- - +"Build line segments for plotting" type Segments{T} pts::Vector{T} end @@ -185,6 +185,7 @@ type SegmentsIterator args::Tuple n::Int end + function iter_segments(args...) tup = Plots.wraptuple(args) n = maximum(map(length, tup)) From eea30fa2530ccba74c995579a8f6aa8e47b6ceb2 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sat, 19 Aug 2017 10:34:06 +0100 Subject: [PATCH 26/68] added ribbon to plotly --- src/backends/plotly.jl | 26 +++++++++++++++++++------- src/utils.jl | 8 ++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9e0537ce..232a886e 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -438,7 +438,8 @@ function plotly_series(plt::Plot, series::Series) isscatter = st in (:scatter, :scatter3d, :scattergl) hasmarker = isscatter || series[:markershape] != :none hasline = st in (:path, :path3d) - hasfillrange = st in (:path, :scatter, :scattergl) && isa(series[:fillrange], AbstractVector) + hasfillrange = st in (:path, :scatter, :scattergl) && + (isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple)) # for surface types, set the data if st in (:heatmap, :contour, :surface, :wireframe) @@ -462,7 +463,7 @@ function plotly_series(plt::Plot, series::Series) else hasline ? "lines" : "none" end - if series[:fillrange] == true || series[:fillrange] == 0 + if series[:fillrange] == true || series[:fillrange] == 0 || isa(series[:fillrange], Tuple) d_out[:fill] = "tozeroy" d_out[:fillcolor] = rgba_string(series[:fillcolor]) elseif isa(series[:fillrange], AbstractVector) @@ -587,11 +588,22 @@ function plotly_series(plt::Plot, series::Series) if hasfillrange # if hasfillrange is true, return two dictionaries (one for original # series, one for series being filled to) instead of one - d_out_fillrange = copy(d_out) - d_out_fillrange[:y] = series[:fillrange] - d_out_fillrange[:showlegend] = false - delete!(d_out_fillrange, :fill) - delete!(d_out_fillrange, :fillcolor) + d_out_fillrange = deepcopy(d_out) + if isa(series[:fillrange], AbstractVector) + d_out_fillrange[:y] = series[:fillrange] + d_out_fillrange[:showlegend] = false + delete!(d_out_fillrange, :fill) + delete!(d_out_fillrange, :fillcolor) + else + # if fillrange is a tuple with upper and lower limit, d_out_fillrange + # is the series that will do the filling + d_out_fillrange[:x], d_out_fillrange[:y] = + concatenate_fillrange(series[:x], series[:fillrange]) + d_out_fillrange[:line][:width] = 0 + d_out[:showlegend] = false + delete!(d_out, :fill) + delete!(d_out, :fillcolor) + end return [d_out_fillrange, d_out] else diff --git a/src/utils.jl b/src/utils.jl index 7e67f877..d3a9849c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -498,6 +498,14 @@ function make_fillrange_from_ribbon(kw::KW) kw[:fillrange] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) end +#turn tuple of fillranges to one path +function concatenate_fillrange(x,y::Tuple) + rib1, rib2 = first(y), last(y) + yline = vcat(rib1,(rib2)[end:-1:1]) + xline = vcat(x,x[end:-1:1]) + return xline, yline +end + function get_sp_lims(sp::Subplot, letter::Symbol) axis_limits(sp[Symbol(letter, :axis)]) end From db3dca1d73ea8d046177b8126ae0bda127346302 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sun, 20 Aug 2017 11:46:21 +0100 Subject: [PATCH 27/68] changed ribbon legend to line --- src/backends/plotly.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 232a886e..1bd9f096 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -589,9 +589,9 @@ function plotly_series(plt::Plot, series::Series) # if hasfillrange is true, return two dictionaries (one for original # series, one for series being filled to) instead of one d_out_fillrange = deepcopy(d_out) + d_out_fillrange[:showlegend] = false if isa(series[:fillrange], AbstractVector) d_out_fillrange[:y] = series[:fillrange] - d_out_fillrange[:showlegend] = false delete!(d_out_fillrange, :fill) delete!(d_out_fillrange, :fillcolor) else @@ -600,7 +600,6 @@ function plotly_series(plt::Plot, series::Series) d_out_fillrange[:x], d_out_fillrange[:y] = concatenate_fillrange(series[:x], series[:fillrange]) d_out_fillrange[:line][:width] = 0 - d_out[:showlegend] = false delete!(d_out, :fill) delete!(d_out, :fillcolor) end From e164ea4b463cf199a83b2bfcdd627c23d42e125c Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sun, 20 Aug 2017 14:06:15 +0100 Subject: [PATCH 28/68] added default transparency to ribbon --- src/backends/gr.jl | 2 +- src/utils.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index c2bf46ef..3622402b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1096,7 +1096,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) st = series[:seriestype] gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) - if st == :shape || series[:fillrange] != nothing + if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing gr_set_fill(series[:fillcolor]) #, series[:fillalpha]) l, r = xpos-0.07, xpos-0.01 b, t = ypos-0.4dy, ypos+0.4dy diff --git a/src/utils.jl b/src/utils.jl index d3a9849c..8c5986fc 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -496,6 +496,7 @@ function make_fillrange_from_ribbon(kw::KW) 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) end #turn tuple of fillranges to one path From d76a6d1c38afb96be113e05c5797cf7c4660f7b2 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 20 Aug 2017 15:43:52 +0200 Subject: [PATCH 29/68] Allow and as ticks --- src/axes.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 734f2154..2bef9b4b 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -216,7 +216,7 @@ end # return (continuous_values, discrete_values) for the ticks on this axis function get_ticks(axis::Axis) - ticks = axis[:ticks] + ticks = _transform_ticks(axis[:ticks]) ticks in (nothing, false) && return nothing dvals = axis[:discrete_values] @@ -246,6 +246,10 @@ function get_ticks(axis::Axis) end end +_transform_ticks(ticks) = ticks +_transform_ticks(ticks::AbstractArray{T}) where T <: Dates.TimeType = Dates.value.(ticks) +_transform_ticks(ticks::NTuple{2, Any}) = (_transform_ticks(ticks[1]), ticks[2]) + # ------------------------------------------------------------------------- From be4a3741224afc04d64c805a845d762ca64f2a69 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 20 Aug 2017 21:55:21 +0200 Subject: [PATCH 30/68] allow turning on/off the axes border --- src/arg_desc.jl | 1 + src/args.jl | 2 ++ src/axes.jl | 8 ++++---- src/backends/glvisualize.jl | 3 ++- src/backends/gr.jl | 1 + src/backends/pyplot.jl | 7 +++++++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ee1e99d8..f3b56493 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -93,6 +93,7 @@ const _arg_desc = KW( :bottom_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding on the bottom of the subplot.", :subplot_index => "Integer. Internal (not set by user). Specifies the index of this subplot in the Plot's `plt.subplot` list.", :colorbar_title => "String. Title of colorbar.", +:draw_axes_border => "Bool. Draw a border around the axes.", # axis args :guide => "String. Axis guide (label).", diff --git a/src/args.jl b/src/args.jl index 37dd250e..4665f964 100644 --- a/src/args.jl +++ b/src/args.jl @@ -282,6 +282,7 @@ const _subplot_defaults = KW( :bottom_margin => :match, :subplot_index => -1, :colorbar_title => "", + :draw_axes_border => false, ) const _axis_defaults = KW( @@ -493,6 +494,7 @@ add_aliases(:orientation, :direction, :dir) add_aliases(:inset_subplots, :inset, :floating) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) +add_aliases(:draw_axes_border, :axes_border, :show_axes_border) # add all pluralized forms to the _keyAliases dict diff --git a/src/axes.jl b/src/axes.jl index 734f2154..22c868ff 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -502,10 +502,10 @@ function axis_drawing_info(sp::Subplot) t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) push!(xspine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine - # push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine + sp[:draw_axes_border] && push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine for xtick in xticks[1] push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick - # push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick + # sp[:draw_axes_border] && push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid end end @@ -517,10 +517,10 @@ function axis_drawing_info(sp::Subplot) t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) push!(yspine_segs, (xmin,ymin), (xmin,ymax)) # left spine - # push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine + sp[:draw_axes_border] && push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine for ytick in yticks[1] push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick - # push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick + # sp[:draw_axes_border] && push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid end end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 60c1730a..91deb56c 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -39,7 +39,8 @@ const _glvisualize_attr = merge_with_base_supported([ :clims, :inset_subplots, :dpi, - :hover + :hover, + :draw_axes_border, ]) const _glvisualize_seriestype = [ :path, :shape, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 3622402b..0c01b8f4 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -32,6 +32,7 @@ const _gr_attr = merge_with_base_supported([ :inset_subplots, :bar_width, :arrow, + :draw_axes_border, ]) const _gr_seriestype = [ :path, :scatter, diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 4b185e6e..ea143e1e 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -32,6 +32,7 @@ const _pyplot_attr = merge_with_base_supported([ :inset_subplots, :dpi, :colorbar_title, + :draw_axes_border, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, @@ -1088,6 +1089,12 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # this sets the bg color inside the grid ax[set_facecolor_sym](py_color(sp[:background_color_inside])) + + if !sp[:draw_axes_border] + # hide the right and top spines + ax[:spines]["right"][:set_visible](false) + ax[:spines]["top"][:set_visible](false) + end end py_drawfig(fig) end From be8c66adc9da0d5c79743863ad9f3f5f2fc6d99e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 20 Aug 2017 22:45:30 +0200 Subject: [PATCH 31/68] fix polar plots on pyplot --- src/backends/pyplot.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ea143e1e..5e4d4c82 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1091,9 +1091,15 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) ax[set_facecolor_sym](py_color(sp[:background_color_inside])) if !sp[:draw_axes_border] - # hide the right and top spines - ax[:spines]["right"][:set_visible](false) - ax[:spines]["top"][:set_visible](false) + if ispolar(sp) + for (loc, spine) in ax[:spines] + spine[:set_visible](false) + end + else + # hide the right and top spines + ax[:spines]["right"][:set_visible](false) + ax[:spines]["top"][:set_visible](false) + end end end py_drawfig(fig) From 113751323678bcfadaf4741866e33ecfe9e51ac5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 21 Aug 2017 00:07:44 +0200 Subject: [PATCH 32/68] add aliases :box and :frame --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 4665f964..5daf08e8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -494,7 +494,7 @@ add_aliases(:orientation, :direction, :dir) add_aliases(:inset_subplots, :inset, :floating) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) -add_aliases(:draw_axes_border, :axes_border, :show_axes_border) +add_aliases(:draw_axes_border, :axes_border, :show_axes_border, :box, :frame) # add all pluralized forms to the _keyAliases dict From 25774ee4c3ff86e706ec0dd5b8e9ae6ba81498e9 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 21 Aug 2017 10:19:47 +0200 Subject: [PATCH 33/68] Turn off gui for pyplot in ijulia --- src/output.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/output.jl b/src/output.jl index 14f15c30..41cc9d0c 100644 --- a/src/output.jl +++ b/src/output.jl @@ -278,6 +278,7 @@ using Requires show(io, MIME("text/html"), plt) end + ENV["MPLBACKEND"] = "Agg" set_ijulia_output("text/html") end end From 9529246bfb20eaf8101fe7a9e7f671c04c0fc7be Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 21 Aug 2017 14:30:44 +0100 Subject: [PATCH 34/68] keywords arguments of same length as series get grouped --- src/args.jl | 2 +- src/series.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 37dd250e..ef403a04 100644 --- a/src/args.jl +++ b/src/args.jl @@ -854,7 +854,7 @@ end # expecting a mapping of "group label" to "group indices" function extractGroupArgs{T, V<:AVec{Int}}(idxmap::Dict{T,V}, args...) groupLabels = sortedkeys(idxmap) - groupIds = VecI[collect(idxmap[k]) for k in groupLabels] + groupIds = Vector{Int}[collect(idxmap[k]) for k in groupLabels] GroupBy(groupLabels, groupIds) end diff --git a/src/series.jl b/src/series.jl index ca520168..746e206d 100644 --- a/src/series.jl +++ b/src/series.jl @@ -515,6 +515,13 @@ end @series begin label --> string(glab) idxfilter --> groupby.groupIds[i] + for (key,val) in d + length(args) == 0 && break + if key != :group && isa(val, AbstractArray) && size(val,1) == size(args[1],1) + n = ndims(val) + :($key) := val[groupby.groupIds[i], fill(Colon(), n-1)...] + end + end args end end From 6dba32bf9989fbb3713d4da661984b773af878d5 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 21 Aug 2017 15:53:31 +0100 Subject: [PATCH 35/68] only check kw is at least as long as group --- src/series.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/series.jl b/src/series.jl index 746e206d..f4f277a8 100644 --- a/src/series.jl +++ b/src/series.jl @@ -511,13 +511,13 @@ end # split the group into 1 series per group, and set the label and idxfilter for each @recipe function f(groupby::GroupBy, args...) + lengthGroup = maximum(union(groupby.groupIds...)) for (i,glab) in enumerate(groupby.groupLabels) @series begin label --> string(glab) idxfilter --> groupby.groupIds[i] for (key,val) in d - length(args) == 0 && break - if key != :group && isa(val, AbstractArray) && size(val,1) == size(args[1],1) + if key != :group && isa(val, AbstractArray) && size(val,1) >= lengthGroup n = ndims(val) :($key) := val[groupby.groupIds[i], fill(Colon(), n-1)...] end From 34f9cfaa0211e6fb0c7483c6e5a4f4f4d96b28c1 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 23 Aug 2017 00:27:33 -0700 Subject: [PATCH 36/68] Remove the -pre Plots.jl is no longer tested on the prereleases so it shouldn't say that they are supported. --- REQUIRE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REQUIRE b/REQUIRE index 6b96e23e..888aaf7d 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ -julia 0.6-pre +julia 0.6 RecipesBase 0.2.0 PlotUtils 0.4.1 From f751b1b7ff901d86402ea1ac1bb1167d52b393be Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Wed, 23 Aug 2017 01:45:54 +0100 Subject: [PATCH 37/68] don't draw fill for 1D markers in gr --- src/backends/gr.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 3622402b..c90c26b8 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -326,7 +326,10 @@ function gr_draw_markers(series::Series, x, y, msize, mz) cfuncind(ci) GR.settransparency(_gr_gradient_alpha[ci-999]) end - gr_draw_marker(x[i], y[i], msi, shape) + # don't draw filled area if marker shape is 1D + if !(shape in (:hline, :vline, :+, :x, :cross, :xcross)) + gr_draw_marker(x[i], y[i], msi, shape) + end end end end From e16125cb507438c9399d1ea499933ca46ecf474f Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Wed, 23 Aug 2017 13:49:33 +0100 Subject: [PATCH 38/68] some GR margin fixes --- src/backends/gr.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index c90c26b8..d1924446 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -326,7 +326,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz) cfuncind(ci) GR.settransparency(_gr_gradient_alpha[ci-999]) end - # don't draw filled area if marker shape is 1D + # don't draw filled area if marker shape is 1D if !(shape in (:hline, :vline, :+, :x, :cross, :xcross)) gr_draw_marker(x[i], y[i], msi, shape) end @@ -543,10 +543,10 @@ end function _update_min_padding!(sp::Subplot{GRBackend}) - leftpad = 10mm - toppad = 2mm - rightpad = 2mm - bottompad = 6mm + leftpad = 10mm + sp[:left_margin] + toppad = 2mm + sp[:top_margin] + rightpad = 2mm + sp[:right_margin] + bottompad = 6mm + sp[:bottom_margin] if sp[:title] != "" toppad += 5mm end @@ -558,10 +558,11 @@ function _update_min_padding!(sp::Subplot{GRBackend}) valign = :top, color = sp[:xaxis][:foreground_color_axis], rotation = sp[:xaxis][:rotation]) - h = 0 + h = 0.0 for (cv, dv) in zip(xticks...) tbx, tby = gr_inqtext(0, 0, string(dv)) - h = max(h, tby[2] - tby[1]) + tby_min, tby_max = extrema(tby) + h = max(h, tby_max - tby_min) end bottompad += 1mm + gr_plot_size[2] * h * px else From b3b533db94c58b1dc666bb6722cbc9426141028b Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Wed, 23 Aug 2017 14:10:35 +0100 Subject: [PATCH 39/68] fix margin in case there is no label (gr) --- src/backends/gr.jl | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d1924446..4a3c06ee 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -543,32 +543,36 @@ end function _update_min_padding!(sp::Subplot{GRBackend}) + # Add margin given by the user leftpad = 10mm + sp[:left_margin] toppad = 2mm + sp[:top_margin] - rightpad = 2mm + sp[:right_margin] - bottompad = 6mm + sp[:bottom_margin] + rightpad = 4mm + sp[:right_margin] + bottompad = 2mm + sp[:bottom_margin] + # Add margin for title if sp[:title] != "" toppad += 5mm end - if sp[:xaxis][:guide] != "" - xticks = axis_drawing_info(sp)[1] - if !(xticks in (nothing, false)) - gr_set_font(sp[:xaxis][:tickfont], - halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], - valign = :top, - color = sp[:xaxis][:foreground_color_axis], - rotation = sp[:xaxis][:rotation]) - h = 0.0 - for (cv, dv) in zip(xticks...) - tbx, tby = gr_inqtext(0, 0, string(dv)) - tby_min, tby_max = extrema(tby) - h = max(h, tby_max - tby_min) - end - bottompad += 1mm + gr_plot_size[2] * h * px - else - bottompad += 4mm + # Add margin for x ticks + xticks = axis_drawing_info(sp)[1] + if !(xticks in (nothing, false)) + gr_set_font(sp[:xaxis][:tickfont], + halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], + valign = :top, + color = sp[:xaxis][:foreground_color_axis], + rotation = sp[:xaxis][:rotation]) + h = 0.0 + for (cv, dv) in zip(xticks...) + tbx, tby = gr_inqtext(0, 0, string(dv)) + tby_min, tby_max = extrema(tby) + h = max(h, tby_max - tby_min) end + bottompad += 1mm + gr_plot_size[2] * h * px end + # Add margin for x label + if sp[:xaxis][:guide] != "" + bottompad += 4mm + end + # Add margin for y label if sp[:yaxis][:guide] != "" leftpad += 4mm end From 06115f25bad8114c187f4b32a013b55236ae46ec Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Wed, 23 Aug 2017 17:43:06 +0100 Subject: [PATCH 40/68] factorize tickfont --- src/backends/gr.jl | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 4a3c06ee..12fd42de 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -542,6 +542,30 @@ function gr_display(plt::Plot) end +function gr_set_xticks_font(sp) + flip = sp[:yaxis][:flip] + mirror = sp[:xaxis][:mirror] + gr_set_font(sp[:xaxis][:tickfont], + halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], + valign = (mirror ? :bottom : :top), + color = sp[:xaxis][:foreground_color_axis], + rotation = sp[:xaxis][:rotation]) + return flip, mirror +end + + +function gr_set_yticks_font(sp) + flip = sp[:xaxis][:flip] + mirror = sp[:yaxis][:mirror] + gr_set_font(sp[:yaxis][:tickfont], + halign = (mirror ? :left : :right), + valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2], + color = sp[:yaxis][:foreground_color_axis], + rotation = sp[:yaxis][:rotation]) + return flip, mirror +end + + function _update_min_padding!(sp::Subplot{GRBackend}) # Add margin given by the user leftpad = 10mm + sp[:left_margin] @@ -747,13 +771,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if !(xticks in (nothing, false)) # x labels - flip = sp[:yaxis][:flip] - mirror = sp[:xaxis][:mirror] - gr_set_font(sp[:xaxis][:tickfont], - halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], - valign = (mirror ? :bottom : :top), - color = sp[:xaxis][:foreground_color_axis], - rotation = sp[:xaxis][:rotation]) + flip, mirror = gr_set_xticks_font(sp) for (cv, dv) in zip(xticks...) # use xor ($) to get the right y coords xi, yi = GR.wctondc(cv, xor(flip, mirror) ? ymax : ymin) @@ -764,13 +782,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if !(yticks in (nothing, false)) # y labels - flip = sp[:xaxis][:flip] - mirror = sp[:yaxis][:mirror] - gr_set_font(sp[:yaxis][:tickfont], - halign = (mirror ? :left : :right), - valign = (:top, :vcenter, :bottom)[sign(sp[:yaxis][:rotation]) + 2], - color = sp[:yaxis][:foreground_color_axis], - rotation = sp[:yaxis][:rotation]) + flip, mirror = gr_set_yticks_font(sp) for (cv, dv) in zip(yticks...) # use xor ($) to get the right y coords xi, yi = GR.wctondc(xor(flip, mirror) ? xmax : xmin, cv) From 91158b1c20708375082301d9a272c33b3b135157 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Wed, 23 Aug 2017 18:00:39 +0100 Subject: [PATCH 41/68] add proper pad for ticks --- src/backends/gr.jl | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 12fd42de..515aaa7e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -565,10 +565,19 @@ function gr_set_yticks_font(sp) return flip, mirror end +function gr_get_ticks_size(ticks, i) + l = 0.0 + for (cv, dv) in zip(ticks...) + tb = gr_inqtext(0, 0, string(dv))[i] + tb_min, tb_max = extrema(tb) + l = max(l, tb_max - tb_min) + end + return l +end function _update_min_padding!(sp::Subplot{GRBackend}) # Add margin given by the user - leftpad = 10mm + sp[:left_margin] + leftpad = 2mm + sp[:left_margin] toppad = 2mm + sp[:top_margin] rightpad = 4mm + sp[:right_margin] bottompad = 2mm + sp[:bottom_margin] @@ -576,21 +585,25 @@ function _update_min_padding!(sp::Subplot{GRBackend}) if sp[:title] != "" toppad += 5mm end - # Add margin for x ticks - xticks = axis_drawing_info(sp)[1] + # Add margin for x and y ticks + xticks, yticks = axis_drawing_info(sp)[1:2] if !(xticks in (nothing, false)) - gr_set_font(sp[:xaxis][:tickfont], - halign = (:left, :hcenter, :right)[sign(sp[:xaxis][:rotation]) + 2], - valign = :top, - color = sp[:xaxis][:foreground_color_axis], - rotation = sp[:xaxis][:rotation]) - h = 0.0 - for (cv, dv) in zip(xticks...) - tbx, tby = gr_inqtext(0, 0, string(dv)) - tby_min, tby_max = extrema(tby) - h = max(h, tby_max - tby_min) + flip, mirror = gr_set_xticks_font(sp) + l = gr_get_ticks_size(xticks, 2) + if mirror + toppad += 1mm + gr_plot_size[2] * l * px + else + bottompad += 1mm + gr_plot_size[2] * l * px + end + end + if !(yticks in (nothing, false)) + flip, mirror = gr_set_yticks_font(sp) + l = gr_get_ticks_size(yticks, 1) + if mirror + rightpad += 1mm + gr_plot_size[1] * l * px + else + leftpad += 1mm + gr_plot_size[1] * l * px end - bottompad += 1mm + gr_plot_size[2] * h * px end # Add margin for x label if sp[:xaxis][:guide] != "" From 5a2d39320f3cc499fd0b297886f96fe6e956e2d3 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 24 Aug 2017 16:13:01 +0200 Subject: [PATCH 42/68] framestyle attribute for gr, pyplot and glvisualize --- src/arg_desc.jl | 2 +- src/args.jl | 18 ++++++++++++++-- src/axes.jl | 42 +++++++++++++++++++++---------------- src/backends/glvisualize.jl | 13 ++++++++++-- src/backends/gr.jl | 20 ++++++++++++++---- src/backends/pyplot.jl | 36 +++++++++++++++++++++++-------- 6 files changed, 95 insertions(+), 36 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index f3b56493..2aad42a5 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -93,7 +93,7 @@ const _arg_desc = KW( :bottom_margin => "Measure (multiply by `mm`, `px`, etc) or `:match` (matches `:margin`). Specifies the extra padding on the bottom of the subplot.", :subplot_index => "Integer. Internal (not set by user). Specifies the index of this subplot in the Plot's `plt.subplot` list.", :colorbar_title => "String. Title of colorbar.", -:draw_axes_border => "Bool. Draw a border around the axes.", +:framestyle => "Symbol. Style of the axes frame. Choose from $(_allFramestyles)", # axis args :guide => "String. Axis guide (label).", diff --git a/src/args.jl b/src/args.jl index 5daf08e8..bc9ce5af 100644 --- a/src/args.jl +++ b/src/args.jl @@ -181,6 +181,14 @@ function hasgrid(arg::Symbol, letter) end hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter) +const _allFramestyles = [:box, :semi, :axes, :grid, :none] +const _framestyleAliases = Dict{Symbol, Symbol}( + :frame => :box, + :border => :box, + :on => :box, + :transparent => :semi, + :semitransparent => :semi, +) # ----------------------------------------------------------------------------- const _series_defaults = KW( @@ -282,7 +290,7 @@ const _subplot_defaults = KW( :bottom_margin => :match, :subplot_index => -1, :colorbar_title => "", - :draw_axes_border => false, + :framestyle => :axes, ) const _axis_defaults = KW( @@ -494,7 +502,7 @@ add_aliases(:orientation, :direction, :dir) add_aliases(:inset_subplots, :inset, :floating) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) -add_aliases(:draw_axes_border, :axes_border, :show_axes_border, :box, :frame) +add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box) # add all pluralized forms to the _keyAliases dict @@ -721,6 +729,7 @@ function preprocessArgs!(d::KW) if haskey(d, :axis) && d[:axis] in (:none, nothing, false) d[:ticks] = nothing d[:foreground_color_border] = RGBA(0,0,0,0) + d[:foreground_color_axis] = RGBA(0,0,0,0) d[:grid] = false delete!(d, :axis) end @@ -823,6 +832,11 @@ function preprocessArgs!(d::KW) d[:colorbar] = convertLegendValue(d[:colorbar]) end + + if haskey(d, :framestyle) && haskey(_framestyleAliases, d[:framestyle]) + d[:framestyle] = _framestyleAliases[d[:framestyle]] + end + # warnings for moved recipes st = get(d, :seriestype, :path) if st in (:boxplot, :violin, :density) && !isdefined(Main, :StatPlots) diff --git a/src/axes.jl b/src/axes.jl index 22c868ff..6b3962a6 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -490,40 +490,46 @@ function axis_drawing_info(sp::Subplot) ymin, ymax = axis_limits(yaxis) xticks = get_ticks(xaxis) yticks = get_ticks(yaxis) - xspine_segs = Segments(2) - yspine_segs = Segments(2) + xaxis_segs = Segments(2) + yaxis_segs = Segments(2) xgrid_segs = Segments(2) ygrid_segs = Segments(2) + xborder_segs = Segments(2) + yborder_segs = Segments(2) - if !(xaxis[:ticks] in (nothing, false)) + if !(sp[:framestyle] == :none) + # xaxis f = scalefunc(yaxis[:scale]) invf = invscalefunc(yaxis[:scale]) t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) - push!(xspine_segs, (xmin,ymin), (xmax,ymin)) # bottom spine - sp[:draw_axes_border] && push!(xspine_segs, (xmin,ymax), (xmax,ymax)) # top spine - for xtick in xticks[1] - push!(xspine_segs, (xtick, ymin), (xtick, t1)) # bottom tick - # sp[:draw_axes_border] && push!(xspine_segs, (xtick, ymax), (xtick, t2)) # top tick - xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid + sp[:framestyle] == :grid || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis + sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine + if !(xaxis[:ticks] in (nothing, false)) + for xtick in xticks[1] + push!(xaxis_segs, (xtick, ymin), (xtick, t1)) # bottom tick + # sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick + xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid + end end - end - if !(yaxis[:ticks] in (nothing, false)) + # yaxis f = scalefunc(xaxis[:scale]) invf = invscalefunc(xaxis[:scale]) t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) - push!(yspine_segs, (xmin,ymin), (xmin,ymax)) # left spine - sp[:draw_axes_border] && push!(yspine_segs, (xmax,ymin), (xmax,ymax)) # right spine - for ytick in yticks[1] - push!(yspine_segs, (xmin, ytick), (t1, ytick)) # left tick - # sp[:draw_axes_border] && push!(yspine_segs, (xmax, ytick), (t2, ytick)) # right tick - yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + sp[:framestyle] == :grid || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis + sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine + if !(yaxis[:ticks] in (nothing, false)) + for ytick in yticks[1] + push!(yaxis_segs, (xmin, ytick), (t1, ytick)) # left tick + # sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick + yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + end end end - xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs + xticks, yticks, xaxis_segs, yaxis_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 91deb56c..1d4fc017 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -40,7 +40,7 @@ const _glvisualize_attr = merge_with_base_supported([ :inset_subplots, :dpi, :hover, - :draw_axes_border, + :framestyle, ]) const _glvisualize_seriestype = [ :path, :shape, @@ -678,7 +678,7 @@ function text_model(font, pivot) end end function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, area) - xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = Plots.axis_drawing_info(sp) + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = Plots.axis_drawing_info(sp) xaxis = sp[:xaxis]; yaxis = sp[:yaxis] xgc = Colors.color(Plots.gl_color(xaxis[:foreground_color_grid])) @@ -728,6 +728,15 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) end + xbc = Colors.color(Plots.gl_color(xaxis[:foreground_color_border])) + ybc = Colors.color(Plots.gl_color(yaxis[:foreground_color_border])) + intensity = sp[:framestyle] == :semi ? 0.5f0 : 1.0f0 + if sp[:framestyle] in (:box, :semi) + xborder = draw_grid_lines(sp, xborder_segs, intensity, :solid, model, RGBA(xbc, intensity)) + yborder = draw_grid_lines(sp, yborder_segs, intensity, :solid, model, RGBA(ybc, intensity)) + push!(axis_vis, xborder, yborder) + end + area_w = GeometryTypes.widths(area) if sp[:title] != "" tf = sp[:titlefont]; color = gl_color(sp[:foreground_color_title]) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 0c01b8f4..60e7df00 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -32,7 +32,7 @@ const _gr_attr = merge_with_base_supported([ :inset_subplots, :bar_width, :arrow, - :draw_axes_border, + :framestyle, ]) const _gr_seriestype = [ :path, :scatter, @@ -609,7 +609,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # TODO: can these be generic flags? outside_ticks = false cmap = false - draw_axes = true + draw_axes = sp[:framestyle] != :none # axes_2d = true for series in series_list(sp) st = series[:seriestype] @@ -711,7 +711,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setwindow(xmin, xmax, ymin, ymax) end - xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs = axis_drawing_info(sp) + xticks, yticks, xspine_segs, yspine_segs, xgrid_segs, ygrid_segs, xborder_segs, yborder_segs = axis_drawing_info(sp) # @show xticks yticks #spine_segs grid_segs # draw the grid lines @@ -729,7 +729,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end GR.settransparency(1.0) - # spine (border) and tick marks + # axis lines gr_set_line(1, :solid, xaxis[:foreground_color_axis]) GR.setclip(0) gr_polyline(coords(xspine_segs)...) @@ -738,6 +738,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_polyline(coords(yspine_segs)...) GR.setclip(1) + # tick marks if !(xticks in (nothing, false)) # x labels flip = sp[:yaxis][:flip] @@ -771,6 +772,17 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_text(xi + (mirror ? 1 : -1) * 1e-2, yi, string(dv)) end end + + # border + intensity = sp[:framestyle] == :semi ? 0.5 : 1.0 + if sp[:framestyle] in (:box, :semi) + gr_set_line(intensity, :solid, xaxis[:foreground_color_border]) + GR.settransparency(intensity) + gr_polyline(coords(xborder_segs)...) + gr_set_line(intensity, :solid, yaxis[:foreground_color_border]) + GR.settransparency(intensity) + gr_polyline(coords(yborder_segs)...) + end end # end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5e4d4c82..5db0ba6b 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -32,7 +32,7 @@ const _pyplot_attr = merge_with_base_supported([ :inset_subplots, :dpi, :colorbar_title, - :draw_axes_border, + :framestyle, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, @@ -1054,7 +1054,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) end py_set_scale(ax, axis) py_set_lims(ax, axis) - py_set_ticks(ax, get_ticks(axis), letter) + ticks = sp[:framestyle] == :none ? nothing : get_ticks(axis) + py_set_ticks(ax, ticks, letter) ax[Symbol("set_", letter, "label")](axis[:guide]) if get(axis.d, :flip, false) ax[Symbol("invert_", letter, "axis")]() @@ -1066,7 +1067,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) lab[:set_family](axis[:tickfont].family) lab[:set_rotation](axis[:rotation]) end - if axis[:grid] + if axis[:grid] && sp[:framestyle] != :none fgcolor = py_color(axis[:foreground_color_grid]) pyaxis[:grid](true, color = fgcolor, @@ -1090,17 +1091,34 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # this sets the bg color inside the grid ax[set_facecolor_sym](py_color(sp[:background_color_inside])) - if !sp[:draw_axes_border] - if ispolar(sp) + # framestyle + if !ispolar(sp) && !is3d(sp) + if sp[:framestyle] == :semi + intensity = 0.5 + ax[:spines]["right"][:set_alpha](intensity) + ax[:spines]["top"][:set_alpha](intensity) + ax[:spines]["right"][:set_linewidth](intensity) + ax[:spines]["top"][:set_linewidth](intensity) + elseif sp[:framestyle] == :axes + ax[:spines]["right"][:set_visible](false) + ax[:spines]["top"][:set_visible](false) + elseif sp[:framestyle] in (:grid, :none) for (loc, spine) in ax[:spines] spine[:set_visible](false) end - else - # hide the right and top spines - ax[:spines]["right"][:set_visible](false) - ax[:spines]["top"][:set_visible](false) end end + # if !sp[:draw_axes_border] + # if ispolar(sp) + # for (loc, spine) in ax[:spines] + # spine[:set_visible](false) + # end + # else + # # hide the right and top spines + # ax[:spines]["right"][:set_visible](false) + # ax[:spines]["top"][:set_visible](false) + # end + # end end py_drawfig(fig) end From 2bbd4cbb17922ad035533bdf8857ff610a288823 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 24 Aug 2017 16:26:54 +0200 Subject: [PATCH 43/68] clean up --- src/args.jl | 2 +- src/axes.jl | 20 ++++++++++---------- src/backends/pyplot.jl | 11 ----------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/args.jl b/src/args.jl index bc9ce5af..0b5750ab 100644 --- a/src/args.jl +++ b/src/args.jl @@ -832,7 +832,7 @@ function preprocessArgs!(d::KW) d[:colorbar] = convertLegendValue(d[:colorbar]) end - + # framestyle if haskey(d, :framestyle) && haskey(_framestyleAliases, d[:framestyle]) d[:framestyle] = _framestyleAliases[d[:framestyle]] end diff --git a/src/axes.jl b/src/axes.jl index 6b3962a6..72745d86 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -499,14 +499,14 @@ function axis_drawing_info(sp::Subplot) if !(sp[:framestyle] == :none) # xaxis - f = scalefunc(yaxis[:scale]) - invf = invscalefunc(yaxis[:scale]) - t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) - t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) - sp[:framestyle] == :grid || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine if !(xaxis[:ticks] in (nothing, false)) + f = scalefunc(yaxis[:scale]) + invf = invscalefunc(yaxis[:scale]) + t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) + t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) + for xtick in xticks[1] push!(xaxis_segs, (xtick, ymin), (xtick, t1)) # bottom tick # sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick @@ -515,14 +515,14 @@ function axis_drawing_info(sp::Subplot) end # yaxis - f = scalefunc(xaxis[:scale]) - invf = invscalefunc(xaxis[:scale]) - t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) - t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) - sp[:framestyle] == :grid || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine if !(yaxis[:ticks] in (nothing, false)) + f = scalefunc(xaxis[:scale]) + invf = invscalefunc(xaxis[:scale]) + t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) + t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) + for ytick in yticks[1] push!(yaxis_segs, (xmin, ytick), (t1, ytick)) # left tick # sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5db0ba6b..03c047bf 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1108,17 +1108,6 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) end end end - # if !sp[:draw_axes_border] - # if ispolar(sp) - # for (loc, spine) in ax[:spines] - # spine[:set_visible](false) - # end - # else - # # hide the right and top spines - # ax[:spines]["right"][:set_visible](false) - # ax[:spines]["top"][:set_visible](false) - # end - # end end py_drawfig(fig) end From d301d2a06b12fa2156ddfe01caa7b58014cc9232 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 24 Aug 2017 16:58:43 +0200 Subject: [PATCH 44/68] fix ticks = nothing on pyplot, ... --- src/args.jl | 2 +- src/backends/gr.jl | 4 ++-- src/backends/pyplot.jl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/args.jl b/src/args.jl index 0b5750ab..f312675f 100644 --- a/src/args.jl +++ b/src/args.jl @@ -432,7 +432,7 @@ add_aliases(:foreground_color_title, :fg_title, :fgtitle, :fgcolor_title, :fg_co add_aliases(:foreground_color_axis, :fg_axis, :fgaxis, :fgcolor_axis, :fg_color_axis, :foreground_axis, :foreground_colour_axis, :fgcolour_axis, :fg_colour_axis, :axiscolor) add_aliases(:foreground_color_border, :fg_border, :fgborder, :fgcolor_border, :fg_color_border, :foreground_border, - :foreground_colour_border, :fgcolour_border, :fg_colour_border, :bordercolor, :border) + :foreground_colour_border, :fgcolour_border, :fg_colour_border, :bordercolor) add_aliases(:foreground_color_text, :fg_text, :fgtext, :fgcolor_text, :fg_color_text, :foreground_text, :foreground_colour_text, :fgcolour_text, :fg_colour_text, :textcolor) add_aliases(:foreground_color_guide, :fg_guide, :fgguide, :fgcolor_guide, :fg_color_guide, :foreground_guide, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 60e7df00..563873b0 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -739,7 +739,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setclip(1) # tick marks - if !(xticks in (nothing, false)) + if !(xticks in (:none, nothing, false)) # x labels flip = sp[:yaxis][:flip] mirror = sp[:xaxis][:mirror] @@ -756,7 +756,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end end - if !(yticks in (nothing, false)) + if !(yticks in (:none, nothing, false)) # y labels flip = sp[:xaxis][:flip] mirror = sp[:yaxis][:mirror] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 03c047bf..80a7f77c 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1067,7 +1067,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) lab[:set_family](axis[:tickfont].family) lab[:set_rotation](axis[:rotation]) end - if axis[:grid] && sp[:framestyle] != :none + if axis[:grid] && !(ticks in (:none, nothing, false)) fgcolor = py_color(axis[:foreground_color_grid]) pyaxis[:grid](true, color = fgcolor, From e2d107a70b215104d4e85f8c7ef657495066f25e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 24 Aug 2017 21:39:33 +0200 Subject: [PATCH 45/68] add framestyle test example --- src/args.jl | 2 +- src/examples.jl | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/args.jl b/src/args.jl index f312675f..5f9e320d 100644 --- a/src/args.jl +++ b/src/args.jl @@ -502,7 +502,7 @@ add_aliases(:orientation, :direction, :dir) add_aliases(:inset_subplots, :inset, :floating) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) -add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box) +add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) # add all pluralized forms to the _keyAliases dict diff --git a/src/examples.jl b/src/examples.jl index 8ae108ef..d1775f47 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -155,7 +155,7 @@ PlotExample("Subplots", """, [:(begin l = @layout([a{0.1h}; b [c;d e]]) - plot(randn(100,5), layout=l, t=[:line :histogram :scatter :steppre :bar], leg=false, ticks=nothing, border=false) + plot(randn(100,5), layout=l, t=[:line :histogram :scatter :steppre :bar], leg=false, ticks=nothing, border=:none) end)] ), @@ -330,7 +330,7 @@ PlotExample("Spy", ), PlotExample("Magic grid argument", - "The grid lines can be modified individually for each axis with the magic grid argument.", + "The grid lines can be modified individually for each axis with the magic `grid` argument.", [:(begin x = rand(10) p1 = plot(x, title = "Default looks") @@ -341,6 +341,14 @@ PlotExample("Magic grid argument", end)] ), +PlotExample("Framestyle", + "The style of the frame/axes of a (sub)plot can be changed with the `framestyle` attribute. The default framestyle is `:axes`.", + [:(begin + histogram(fill(randn(1000), 5), framestyle = [:box :semi :axes :grid :none], + title = [":box" ":semi" ":axes" ":grid" ":none"], color = RowVector(1:5), layout = 5, label = "") + end)] +), + ] # --------------------------------------------------------------------------------- @@ -365,7 +373,7 @@ test_examples(pkgname[, idx]; debug = false, disp = true, sleep = nothing, skip = [], only = nothing Run the `idx` test example for a given backend, or all examples if `idx` -is not specified. +is not specified. """ function test_examples(pkgname::Symbol; debug = false, disp = true, sleep = nothing, skip = [], only = nothing) From a4ed700338a8b946d6b2c130a9386c24c014e27e Mon Sep 17 00:00:00 2001 From: Darwin Darakananda Date: Sat, 20 May 2017 15:44:48 -0700 Subject: [PATCH 46/68] Use `invokelatest` to get around world age issue --- src/pipeline.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pipeline.jl b/src/pipeline.jl index 8879ff6f..e0041b77 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -210,7 +210,7 @@ function _plot_setup(plt::Plot, d::KW, kw_list::Vector{KW}) # TODO: init subplots here _update_plot_args(plt, d) if !plt.init - plt.o = _create_backend_figure(plt) + plt.o = Base.invokelatest(_create_backend_figure, plt) # create the layout and subplots from the inputs plt.layout, plt.subplots, plt.spmap = build_layout(plt.attr) From 54adc343488131151337a1dc8c4acacb43230c62 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 24 Aug 2017 22:21:13 +0200 Subject: [PATCH 47/68] fix glvisualize framestyle :none ticks --- src/backends/glvisualize.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 1d4fc017..974b73b1 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -708,7 +708,7 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are xlim = Plots.axis_limits(xaxis) ylim = Plots.axis_limits(yaxis) - if !(xaxis[:ticks] in (nothing, false, :none)) + if !(xaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none) ticklabels = map(model) do m mirror = xaxis[:mirror] t, positions, offsets = draw_ticks(xaxis, xticks, true, ylim, m) From c0f274d54b2246fc7917c9dc7a1b54371286d7d4 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Thu, 24 Aug 2017 22:27:04 -0400 Subject: [PATCH 48/68] gr: always use NDCs when inquiring text extents --- src/backends/gr.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 092b00d3..43e55d4f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -567,12 +567,15 @@ function gr_set_yticks_font(sp) end function gr_get_ticks_size(ticks, i) + GR.savestate() + GR.selntran(0) l = 0.0 for (cv, dv) in zip(ticks...) tb = gr_inqtext(0, 0, string(dv))[i] tb_min, tb_max = extrema(tb) l = max(l, tb_max - tb_min) end + GR.restorestate() return l end From dbbbeddad0a5b877b94e618fc79827c5bbe7afea Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Thu, 24 Aug 2017 22:27:04 -0400 Subject: [PATCH 49/68] gr: always use NDCs when inquiring text extents --- src/backends/gr.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 092b00d3..43e55d4f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -567,12 +567,15 @@ function gr_set_yticks_font(sp) end function gr_get_ticks_size(ticks, i) + GR.savestate() + GR.selntran(0) l = 0.0 for (cv, dv) in zip(ticks...) tb = gr_inqtext(0, 0, string(dv))[i] tb_min, tb_max = extrema(tb) l = max(l, tb_max - tb_min) end + GR.restorestate() return l end From 6f3301e82ffdbf614d0ad44efcfb939dbf920f46 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 25 Aug 2017 14:16:53 +0200 Subject: [PATCH 50/68] make linecolor default to auto --- src/args.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/args.jl b/src/args.jl index 5f9e320d..203db58f 100644 --- a/src/args.jl +++ b/src/args.jl @@ -198,7 +198,7 @@ const _series_defaults = KW( :seriestype => :path, :linestyle => :solid, :linewidth => :auto, - :linecolor => :match, + :linecolor => :auto, :linealpha => nothing, :fillrange => nothing, # ribbons, areas, etc :fillcolor => :match, @@ -1333,12 +1333,14 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int) # update other colors for s in (:line, :marker, :fill) csym, asym = Symbol(s,:color), Symbol(s,:alpha) - d[csym] = if d[csym] == :match + d[csym] = if d[csym] == :auto plot_color(if has_black_border_for_default(d[:seriestype]) && s == :line sp[:foreground_color_subplot] else d[:seriescolor] end, d[asym]) + elseif d[csym] == :match + plot_color(d[:seriescolor], d[asym]) else getSeriesRGBColor(d[csym], d[asym], sp, plotIndex) end From 509f8f6a95fc21d993498fff993704c9fdcff48e Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Fri, 25 Aug 2017 16:46:07 +0100 Subject: [PATCH 51/68] readd fill for cross and xcross on GR --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 43e55d4f..de1e579e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -328,7 +328,7 @@ function gr_draw_markers(series::Series, x, y, msize, mz) GR.settransparency(_gr_gradient_alpha[ci-999]) end # don't draw filled area if marker shape is 1D - if !(shape in (:hline, :vline, :+, :x, :cross, :xcross)) + if !(shape in (:hline, :vline, :+, :x)) gr_draw_marker(x[i], y[i], msi, shape) end end From 5a7ed24078c23c12875007a767f1f5ecec3e6683 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Fri, 25 Aug 2017 17:01:29 +0100 Subject: [PATCH 52/68] allow tuples --- src/series.jl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/series.jl b/src/series.jl index f4f277a8..f3499e22 100644 --- a/src/series.jl +++ b/src/series.jl @@ -509,6 +509,13 @@ end # nothing # end +splittable_kw(key, val, lengthGroup) = false +splittable_kw(key, val::AbstractArray, lengthGroup) = (key != :group) && size(val,1) == lengthGroup +splittable_kw(key, val::Tuple, lengthGroup) = all(splittable_kw.(key, val, lengthGroup)) + +split_kw(key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val)-1)...] +split_kw(key, val::Tuple, indices) = Tuple(split_kw(key, v, indices) for v in val) + # split the group into 1 series per group, and set the label and idxfilter for each @recipe function f(groupby::GroupBy, args...) lengthGroup = maximum(union(groupby.groupIds...)) @@ -517,9 +524,8 @@ end label --> string(glab) idxfilter --> groupby.groupIds[i] for (key,val) in d - if key != :group && isa(val, AbstractArray) && size(val,1) >= lengthGroup - n = ndims(val) - :($key) := val[groupby.groupIds[i], fill(Colon(), n-1)...] + if splittable_kw(key, val, lengthGroup) + :($key) := split_kw(key, val, groupby.groupIds[i]) end end args From 78b0918216033b195494b7cc55709a2f6e7c212f Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Fri, 25 Aug 2017 13:54:56 -0400 Subject: [PATCH 53/68] gr: defer the calculation of padding constraints --- src/backends/gr.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 43e55d4f..d4d8e3bf 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -579,7 +579,7 @@ function gr_get_ticks_size(ticks, i) return l end -function _update_min_padding!(sp::Subplot{GRBackend}) +function gr_update_min_padding(sp::Subplot{GRBackend}) # Add margin given by the user leftpad = 2mm + sp[:left_margin] toppad = 2mm + sp[:top_margin] @@ -622,6 +622,8 @@ end function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) + gr_update_min_padding(sp) + # the viewports for this subplot viewport_subplot = gr_viewport_from_bbox(sp, bbox(sp), w, h, viewport_canvas) viewport_plotarea[:] = gr_viewport_from_bbox(sp, plotarea(sp), w, h, viewport_canvas) From a5751895f0e3807bb7ce5fff833134bd836671c7 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Sat, 26 Aug 2017 06:49:00 -0400 Subject: [PATCH 54/68] gr: update padding constraints before first plot --- src/backends/gr.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d4d8e3bf..8c32e6ec 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -579,7 +579,7 @@ function gr_get_ticks_size(ticks, i) return l end -function gr_update_min_padding(sp::Subplot{GRBackend}) +function _update_min_padding!(sp::Subplot{GRBackend}) # Add margin given by the user leftpad = 2mm + sp[:left_margin] toppad = 2mm + sp[:top_margin] @@ -620,9 +620,8 @@ function gr_update_min_padding(sp::Subplot{GRBackend}) sp.minpad = (leftpad, toppad, rightpad, bottompad) end - function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) - gr_update_min_padding(sp) + _update_min_padding!(sp) # the viewports for this subplot viewport_subplot = gr_viewport_from_bbox(sp, bbox(sp), w, h, viewport_canvas) From 6cb1ed6c920cc7f95483affe4bd8b952e1fd7e4b Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Sun, 27 Aug 2017 11:08:26 +0200 Subject: [PATCH 55/68] Remove hidden files when checking version numbers --- test/imgcomp.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/imgcomp.jl b/test/imgcomp.jl index f3c0ee22..0a59e0df 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -42,7 +42,8 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is fn = "ref$idx.png" # firgure out version info - versions = sort(VersionNumber.(readdir(refdir)), rev = true) + vns = filter(x->x[1] != '.', readdir(refdir)) + versions = sort(VersionNumber.(vns), rev = true) versions = filter(v -> v <= _current_plots_version, versions) # @show refdir fn versions From 5157089d876aab1f639a7e72d3e952687aaa21da Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sun, 27 Aug 2017 18:56:10 +0100 Subject: [PATCH 56/68] group on a tuple of vectors --- src/args.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/args.jl b/src/args.jl index ef403a04..3bd869f5 100644 --- a/src/args.jl +++ b/src/args.jl @@ -840,16 +840,24 @@ end # this is when given a vector-type of values to group by -function extractGroupArgs(v::AVec, args...) +function extractGroupArgs(v::AVec, args...; legendEntry = string) groupLabels = sort(collect(unique(v))) n = length(groupLabels) if n > 100 warn("You created n=$n groups... Is that intended?") end groupIds = Vector{Int}[filter(i -> v[i] == glab, 1:length(v)) for glab in groupLabels] - GroupBy(map(string, groupLabels), groupIds) + GroupBy(map(legendEntry, groupLabels), groupIds) end +legendEntryFromTuple(ns::Tuple) = string(("$n " for n in ns)...) + +# this is when given a tuple of vectors of values to group by +function extractGroupArgs(vs::Tuple, args...) + (vs == ()) && return GroupBy([""], [1:size(args[1],1)]) + v = collect(zip(vs...)) + extractGroupArgs(v, args...; legendEntry = legendEntryFromTuple) +end # expecting a mapping of "group label" to "group indices" function extractGroupArgs{T, V<:AVec{Int}}(idxmap::Dict{T,V}, args...) From d594ac2f00f7edf2b6d1d246ebb9b06f2dba60de Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 28 Aug 2017 18:16:10 +0100 Subject: [PATCH 57/68] Accept axis with 4 ticks --- src/axes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 6ce1532c..850b67cb 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -185,7 +185,7 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) scaled_ticks = optimize_ticks( sf(amin), sf(amax); - k_min = 5, # minimum number of ticks + k_min = 4, # minimum number of ticks k_max = 8, # maximum number of ticks )[1] elseif typeof(ticks) <: Int From 25bcc3cbc159bc32e354442ef493af2e33a40cb8 Mon Sep 17 00:00:00 2001 From: Jonathan Goldfarb Date: Tue, 29 Aug 2017 12:19:01 -0400 Subject: [PATCH 58/68] Fix incorrect escape sequence error on v0.7. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 203db58f..fb820b65 100644 --- a/src/args.jl +++ b/src/args.jl @@ -175,7 +175,7 @@ function hasgrid(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on) || contains(string(arg), string(letter)) else - warn("Unknown grid argument $arg; $letter\grid was set to `true` instead.") + warn("Unknown grid argument $arg; $letter\\grid was set to `true` instead.") true end end From e3cba22ab7e832c3f8730329133ed881f3157a23 Mon Sep 17 00:00:00 2001 From: Jonathan Goldfarb Date: Tue, 29 Aug 2017 13:29:30 -0400 Subject: [PATCH 59/68] Correct fix to warning for unknown grid argument. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index fb820b65..0d6eeb6f 100644 --- a/src/args.jl +++ b/src/args.jl @@ -175,7 +175,7 @@ function hasgrid(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on) || contains(string(arg), string(letter)) else - warn("Unknown grid argument $arg; $letter\\grid was set to `true` instead.") + warn("Unknown grid argument $arg; $(Symbol(letter, :grid)) was set to `true` instead.") true end end From a894d377dce49058887fff4b0e05e944233a27be Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 29 Aug 2017 23:34:07 +0200 Subject: [PATCH 60/68] add vectors to hold histogram-like seriestypes and friends --- src/args.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/args.jl b/src/args.jl index 6afdd66b..b305d613 100644 --- a/src/args.jl +++ b/src/args.jl @@ -80,9 +80,13 @@ const _typeAliases = Dict{Symbol,Symbol}( add_non_underscore_aliases!(_typeAliases) -like_histogram(seriestype::Symbol) = seriestype in (:histogram, :barhist, :barbins) -like_line(seriestype::Symbol) = seriestype in (:line, :path, :steppre, :steppost) -like_surface(seriestype::Symbol) = seriestype in (:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image) +const _histogram_like = [:histogram, :barhist, :barbins] +const _line_like = [:line, :path, :steppre, :steppost] +const _surface_like = [:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image] + +like_histogram(seriestype::Symbol) = seriestype in _histogram_like +like_line(seriestype::Symbol) = seriestype in _line_like +like_surface(seriestype::Symbol) = seriestype in _surface_like is3d(seriestype::Symbol) = seriestype in _3dTypes is3d(series::Series) = is3d(series.d) From 8beee23e2189c85c9fde568d9bfc01f087b95ac8 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 30 Aug 2017 09:59:23 +0200 Subject: [PATCH 61/68] gr: suppress default output in CI or Jupyter mode _update_min_padding() is called before the backend is "started". In GR, this triggers an automatic initialization and starts the default output driver (X11, Quartz or GDI). This doesn't make sense in headless testing environments (CI) or when using Plots in Jupyter notebooks. These patches correct this behavour - but it's unclear (to me), why the call of _update_min_padding() can't be postponed. --- src/backends/gr.jl | 3 +++ test/runtests.jl | 1 + 2 files changed, 4 insertions(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 177cd1b9..4f871e6a 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -580,6 +580,9 @@ function gr_get_ticks_size(ticks, i) end function _update_min_padding!(sp::Subplot{GRBackend}) + if !haskey(ENV, "GKSwstype") && isijulia() + ENV["GKSwstype"] = "svg" + end # Add margin given by the user leftpad = 2mm + sp[:left_margin] toppad = 2mm + sp[:top_margin] diff --git a/test/runtests.jl b/test/runtests.jl index 69b4d393..da7fcb05 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,7 @@ default(show=false, reuse=true) img_eps = isinteractive() ? 1e-2 : 10e-2 @testset "GR" begin + ENV["GKSwstype"] = "100" @test gr() == Plots.GRBackend() @test backend() == Plots.GRBackend() From c355e02a20db52e845b0d4c22753acc01af6fe90 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Tue, 29 Aug 2017 13:37:06 +0200 Subject: [PATCH 62/68] add nightly and 32-bit to allow-failures --- appveyor.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index cc07d84a..81d2e51f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,12 @@ environment: - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" +matrix: + allow_failures: + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" #check and address + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" + - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + notifications: - provider: Email on_build_success: false From 17c10bbe68b5148b3a1a645401bec275f43af212 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 28 Aug 2017 11:06:51 +0200 Subject: [PATCH 63/68] Reduce margin to 10 px --- src/examples.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples.jl b/src/examples.jl index d1775f47..4393ab60 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -290,7 +290,7 @@ PlotExample("Layouts, margins, label rotation, title location", [:(begin plot(rand(100,6),layout=@layout([a b; c]),title=["A" "B" "C"], title_location=:left, left_margin=[20mm 0mm], - bottom_margin=50px, xrotation=60) + bottom_margin=10px, xrotation=60) end)] ), From e92fbadc3ada19f4162454451961cfe9eebdbde3 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 23 Aug 2017 19:53:33 +0200 Subject: [PATCH 64/68] Update histogram normalization desc --- src/arg_desc.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 2aad42a5..51ae0d80 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -40,7 +40,7 @@ const _arg_desc = KW( :ribbon => "Number or AbstractVector. Creates a fillrange around the data points.", :quiver => "AbstractVector or 2-Tuple of vectors. The directional vectors U,V which specify velocity/gradient vectors for a quiver plot.", :arrow => "nothing (no arrows), Bool (if true, default arrows), Arrow object, or arg(s) that could be style or head length/widths. Defines arrowheads that should be displayed at the end of path line segments (just before a NaN and the last non-NaN point). Used in quiverplot, streamplot, or similar.", -:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a PDF with integral of 1) and :density (only normalize in respect to bin sizes).", +:normalize => "Bool or Symbol. Histogram normalization mode. Possible values are: false/:none (no normalization, default), true/:pdf (normalize to a discrete Probability Density Function, where the total area of the bins is 1), :probability (bin heights sum to 1) and :density (the area of each bin, rather than the height, is equal to the counts - useful for uneven bin sizes).", :weights => "AbstractVector. Used in histogram types for weighted counts.", :contours => "Bool. Add contours to the side-grids of 3D plots? Used in surface/wireframe.", :match_dimensions => "Bool. For heatmap types... should the first dimension of a matrix (rows) correspond to the first dimension of the plot (x-axis)? The default is false, which matches the behavior of Matplotlib, Plotly, and others. Note: when passing a function for z, the function should still map `(x,y) -> z`.", From 62694e4a9382e5efab387bf86e86f7a3c1e4ac63 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 31 Aug 2017 23:19:00 +0200 Subject: [PATCH 65/68] Make Freedman-Diaconis the default --- src/recipes.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 393bc2d4..0708667f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -510,8 +510,10 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode v = vs[dim] if mode == :auto - 30 - elseif mode == :sqrt # Square-root choice + mode == :fd + end + + if mode == :sqrt # Square-root choice _cl(sqrt(n)) elseif mode == :sturges # Sturges' formula _cl(log2(n)) + 1 @@ -550,7 +552,7 @@ end @recipe function f(::Type{Val{:histogram}}, x, y, z) - seriestype := :barhist + seriestype := length(y) > 1e6 ? :stephist : :barhist () end @deps histogram barhist From cd1913c00886e1c5ccc0c1e06ea7aee8bdb83efc Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 31 Aug 2017 23:20:55 +0200 Subject: [PATCH 66/68] Update bins description --- src/arg_desc.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 51ae0d80..8634eabb 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -21,7 +21,7 @@ const _arg_desc = KW( :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.", -:bins => "Integer, NTuple{2,Integer}, AbstractVector or Symbol. Default is :auto. 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. `linspace(extrema(x)..., 25)`", +: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. `linspace(extrema(x)..., 25)`", :smooth => "Bool. Add a regression line?", :group => "AbstractVector. Data is split into a separate series, one for each unique value in `group`.", :x => "Various. Input data. First Dimension", From 4320c7b9fbc6a49d9fa50fb8430ab09568c6b615 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Fri, 1 Sep 2017 07:36:49 +0200 Subject: [PATCH 67/68] gr: suppress default output in Juno --- src/backends/gr.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 4f871e6a..76faa6fd 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -580,8 +580,10 @@ function gr_get_ticks_size(ticks, i) end function _update_min_padding!(sp::Subplot{GRBackend}) - if !haskey(ENV, "GKSwstype") && isijulia() - ENV["GKSwstype"] = "svg" + if !haskey(ENV, "GKSwstype") + if isijulia() || (isdefined(Main, :Juno) && Juno.isactive()) + ENV["GKSwstype"] = "svg" + end end # Add margin given by the user leftpad = 2mm + sp[:left_margin] From d77be82a99a55c468990e8a056fc28b4d6be31c0 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Fri, 1 Sep 2017 10:36:44 +0200 Subject: [PATCH 68/68] fix classic typo --- src/recipes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recipes.jl b/src/recipes.jl index 0708667f..d4d1b201 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -510,7 +510,7 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode v = vs[dim] if mode == :auto - mode == :fd + mode = :fd end if mode == :sqrt # Square-root choice