From c6b7ff6c7585fdc0bb344cfe8cb6ca27c96a4c1b Mon Sep 17 00:00:00 2001 From: AnkurD Date: Tue, 26 Sep 2017 17:16:03 +0900 Subject: [PATCH 001/115] Colorbar takes font style from Y Axis --- src/backends/pyplot.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d9f36015..ff2853f2 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -999,9 +999,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # create and store the colorbar object (handle) and the axis that it is drawn on. # note: the colorbar axis is positioned independently from the subplot axis fig = plt.o - cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) - cb = fig[:colorbar](handle; cax = cbax, kw...) - cb[:set_label](sp[:colorbar_title]) + cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) + cb = fig[:colorbar](handle; cax = cbax, kw...) + cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefont].pointsize),family=sp[:yaxis][:guidefont].family) + for lab in cb[:ax][:yaxis][:get_ticklabels]() + lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) + lab[:set_family](sp[:yaxis][:tickfont].family) + end sp.attr[:cbar_handle] = cb sp.attr[:cbar_ax] = cbax end From 5b3c41bd774f96b6e19aedad119c53df2d77cfb4 Mon Sep 17 00:00:00 2001 From: AnkurD Date: Tue, 26 Sep 2017 17:22:17 +0900 Subject: [PATCH 002/115] Colorbar takes font style from Y Axis --- src/backends/pyplot.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ff2853f2..f5ffbc07 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -999,13 +999,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # create and store the colorbar object (handle) and the axis that it is drawn on. # note: the colorbar axis is positioned independently from the subplot axis fig = plt.o - cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) - cb = fig[:colorbar](handle; cax = cbax, kw...) - cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefont].pointsize),family=sp[:yaxis][:guidefont].family) - for lab in cb[:ax][:yaxis][:get_ticklabels]() - lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) - lab[:set_family](sp[:yaxis][:tickfont].family) - end + cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) + cb = fig[:colorbar](handle; cax = cbax, kw...) + cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefont].pointsize),family=sp[:yaxis][:guidefont].family) + for lab in cb[:ax][:yaxis][:get_ticklabels]() + lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) + lab[:set_family](sp[:yaxis][:tickfont].family) + end sp.attr[:cbar_handle] = cb sp.attr[:cbar_ax] = cbax end From 18188516ec7c02994b57ae7e7ffff03c56edd189 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 Sep 2017 11:48:17 +0200 Subject: [PATCH 003/115] implement showaxis attribute for gr --- src/arg_desc.jl | 3 ++- src/args.jl | 22 ++++++++++++++-- src/axes.jl | 63 +++++++++++++++++++++++++++------------------- src/backends/gr.jl | 52 ++++++++++++++++++++++---------------- 4 files changed, 89 insertions(+), 51 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 88bc8cf8..ce7cde8b 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -115,5 +115,6 @@ const _arg_desc = KW( :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)", -:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`" +:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`", +:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:none`, `:off`" ) diff --git a/src/args.jl b/src/args.jl index 2ceeaa93..83379dfd 100644 --- a/src/args.jl +++ b/src/args.jl @@ -170,8 +170,8 @@ const _scaleAliases = Dict{Symbol,Symbol}( const _allGridSyms = [:x, :y, :z, :xy, :xz, :yx, :yz, :zx, :zy, :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, - :all, :both, :on, - :none, :off,] + :all, :both, :on, :yes, + :none, :off, :no] const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] hasgrid(arg::Void, letter) = false hasgrid(arg::Bool, letter) = arg @@ -185,6 +185,24 @@ function hasgrid(arg::Symbol, letter) end hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter) +const _allShowaxisSyms = [:x, :y, :z, + :xy, :xz, :yx, :yz, :zx, :zy, + :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, + :all, :both, :on, :yes, + :none, :off, :no] +const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)] +showaxis(arg::Void, letter) = false +showaxis(arg::Bool, letter) = arg +function hasgrid(arg::Symbol, letter) + if arg in _allGridSyms + arg in (:all, :both, :on, :yes) || contains(string(arg), string(letter)) + else + warn("Unknown showaxis argument $arg; $(Symbol(letter, :showaxis)) was set to `true` instead.") + true + end +end +showaxis(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter) + const _allFramestyles = [:box, :semi, :axes, :origin, :zerolines, :grid, :none] const _framestyleAliases = Dict{Symbol, Symbol}( :frame => :box, diff --git a/src/axes.jl b/src/axes.jl index f989a8fb..6d06a261 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -70,6 +70,9 @@ function process_axis_arg!(d::KW, arg, letter = "") elseif arg == nothing d[Symbol(letter,:ticks)] = [] + elseif arg in _allShowaxisArgs + d[Symbol(letter,:showaxis)] = showaxis(arg, letter) + elseif typeof(arg) <: Number d[Symbol(letter,:rotation)] = arg @@ -517,16 +520,18 @@ function axis_drawing_info(sp::Subplot) if !(sp[:framestyle] == :none) # xaxis - sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis - if sp[:framestyle] in (:origin, :zerolines) - push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0)) - # don't show the 0 tick label for the origin framestyle - if sp[:framestyle] == :origin && length(xticks) > 1 - showticks = xticks[1] .!= 0 - xticks = (xticks[1][showticks], xticks[2][showticks]) + if xaxis[:showaxis] + sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis + if sp[:framestyle] in (:origin, :zerolines) + push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0)) + # don't show the 0 tick label for the origin framestyle + if sp[:framestyle] == :origin && length(xticks) > 1 + showticks = xticks[1] .!= 0 + xticks = (xticks[1][showticks], xticks[2][showticks]) + end end + sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine end - 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]) @@ -536,28 +541,32 @@ function axis_drawing_info(sp::Subplot) t3 = invf(f(0) + 0.015 * (f(ymax) - f(ymin)) * ticks_in) for xtick in xticks[1] - tick_start, tick_stop = if sp[:framestyle] == :origin - (0, t3) - else - xaxis[:mirror] ? (ymax, t2) : (ymin, t1) + if xaxis[:showaxis] + tick_start, tick_stop = if sp[:framestyle] == :origin + (0, t3) + else + xaxis[:mirror] ? (ymax, t2) : (ymin, t1) + end + push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick end - push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # 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 # yaxis - sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis - if sp[:framestyle] in (:origin, :zerolines) - push!(yaxis_segs, (0.0, ymin), (0.0, ymax)) - # don't show the 0 tick label for the origin framestyle - if sp[:framestyle] == :origin && length(yticks) > 1 - showticks = yticks[1] .!= 0 - yticks = (yticks[1][showticks], yticks[2][showticks]) + if yaxis[:showaxis] + sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis + if sp[:framestyle] in (:origin, :zerolines) + push!(yaxis_segs, (0.0, ymin), (0.0, ymax)) + # don't show the 0 tick label for the origin framestyle + if sp[:framestyle] == :origin && length(yticks) > 1 + showticks = yticks[1] .!= 0 + yticks = (yticks[1][showticks], yticks[2][showticks]) + end end + sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine end - 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]) @@ -567,12 +576,14 @@ function axis_drawing_info(sp::Subplot) t3 = invf(f(0) + 0.015 * (f(xmax) - f(xmin)) * ticks_in) for ytick in yticks[1] - tick_start, tick_stop = if sp[:framestyle] == :origin - (0, t3) - else - yaxis[:mirror] ? (xmax, t2) : (xmin, t1) + if yaxis[:showaxis] + tick_start, tick_stop = if sp[:framestyle] == :origin + (0, t3) + else + yaxis[:mirror] ? (xmax, t2) : (xmin, t1) + end + push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick end - push!(ytick_segs, (tick_start, ytick), (tick_stop, 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 diff --git a/src/backends/gr.jl b/src/backends/gr.jl index fcd93547..3bad3a0f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -793,35 +793,43 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.settransparency(1.0) # axis lines - gr_set_line(1, :solid, xaxis[:foreground_color_axis]) - GR.setclip(0) - gr_polyline(coords(xspine_segs)...) - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - GR.setclip(0) - gr_polyline(coords(yspine_segs)...) + if xaxis[:showaxis] + gr_set_line(1, :solid, xaxis[:foreground_color_axis]) + GR.setclip(0) + gr_polyline(coords(xspine_segs)...) + end + if yaxis[:showaxis] + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + GR.setclip(0) + gr_polyline(coords(yspine_segs)...) + end GR.setclip(1) # axis ticks - if sp[:framestyle] in (:zerolines, :grid) - gr_set_line(1, :solid, xaxis[:foreground_color_grid]) - GR.settransparency(xaxis[:gridalpha]) - else - gr_set_line(1, :solid, xaxis[:foreground_color_axis]) + if xaxis[:showaxis] + if sp[:framestyle] in (:zerolines, :grid) + gr_set_line(1, :solid, xaxis[:foreground_color_grid]) + GR.settransparency(xaxis[:gridalpha]) + else + gr_set_line(1, :solid, xaxis[:foreground_color_axis]) + end + GR.setclip(0) + gr_polyline(coords(xtick_segs)...) end - GR.setclip(0) - gr_polyline(coords(xtick_segs)...) - if sp[:framestyle] in (:zerolines, :grid) - gr_set_line(1, :solid, yaxis[:foreground_color_grid]) - GR.settransparency(yaxis[:gridalpha]) - else - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + if yaxis[:showaxis] + if sp[:framestyle] in (:zerolines, :grid) + gr_set_line(1, :solid, yaxis[:foreground_color_grid]) + GR.settransparency(yaxis[:gridalpha]) + else + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + end + GR.setclip(0) + gr_polyline(coords(ytick_segs)...) end - GR.setclip(0) - gr_polyline(coords(ytick_segs)...) GR.setclip(1) # tick marks - if !(xticks in (:none, nothing, false)) + if !(xticks in (:none, nothing, false)) && xaxis[:showaxis] # x labels flip, mirror = gr_set_xticks_font(sp) for (cv, dv) in zip(xticks...) @@ -832,7 +840,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end end - if !(yticks in (:none, nothing, false)) + if !(yticks in (:none, nothing, false)) && yaxis[:showaxis] # y labels flip, mirror = gr_set_yticks_font(sp) for (cv, dv) in zip(yticks...) From ee7a3b36864c4a94e2bc3e86dfb588cf9bc49540 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 Sep 2017 13:41:54 +0200 Subject: [PATCH 004/115] general axis fixes and improvemennts --- src/arg_desc.jl | 4 ++-- src/args.jl | 36 ++++++++++++++++++++++-------------- src/axes.jl | 4 ++-- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ce7cde8b..ce24b8e0 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -110,11 +110,11 @@ 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, Symbol, String or `nothing`. Show the grid lines? `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:none`, `:off`", +:grid => "Bool, Symbol, String or `nothing`. Show the grid lines? `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `: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)", :tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`", -:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:none`, `:off`" +:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`" ) diff --git a/src/args.jl b/src/args.jl index 83379dfd..3ea3efde 100644 --- a/src/args.jl +++ b/src/args.jl @@ -170,8 +170,8 @@ const _scaleAliases = Dict{Symbol,Symbol}( const _allGridSyms = [:x, :y, :z, :xy, :xz, :yx, :yz, :zx, :zy, :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, - :all, :both, :on, :yes, - :none, :off, :no] + :all, :both, :on, :yes, :show, + :none, :off, :no, :hide] const _allGridArgs = [_allGridSyms; string.(_allGridSyms); nothing] hasgrid(arg::Void, letter) = false hasgrid(arg::Bool, letter) = arg @@ -188,12 +188,12 @@ hasgrid(arg::AbstractString, letter) = hasgrid(Symbol(arg), letter) const _allShowaxisSyms = [:x, :y, :z, :xy, :xz, :yx, :yz, :zx, :zy, :xyz, :xzy, :yxz, :yzx, :zxy, :zyx, - :all, :both, :on, :yes, - :none, :off, :no] + :all, :both, :on, :yes, :show, + :off, :no, :hide] const _allShowaxisArgs = [_allGridSyms; string.(_allGridSyms)] showaxis(arg::Void, letter) = false showaxis(arg::Bool, letter) = arg -function hasgrid(arg::Symbol, letter) +function showaxis(arg::Symbol, letter) if arg in _allGridSyms arg in (:all, :both, :on, :yes) || contains(string(arg), string(letter)) else @@ -340,7 +340,8 @@ const _axis_defaults = KW( :gridalpha => 0.1, :gridstyle => :solid, :gridlinewidth => 0.5, - :tick_direction => :in, + :tick_direction => :in, + :showaxis => true, ) const _suppress_warnings = Set{Symbol}([ @@ -728,7 +729,7 @@ function processGridArg!(d::KW, arg, letter) d[Symbol(letter, :gridlinewidth)] = arg # color -elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_grid)) + elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_grid)) warn("Skipped grid arg $arg.") end @@ -753,13 +754,13 @@ function preprocessArgs!(d::KW) replaceAliases!(d, _keyAliases) # clear all axis stuff - 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 + # 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 # for letter in (:x, :y, :z) # asym = Symbol(letter, :axis) # if haskey(d, asym) || d[asym] in (:none, nothing, false) @@ -768,6 +769,13 @@ function preprocessArgs!(d::KW) # end # end + # handle axis args common to all axis + args = pop!(d, :axis, ()) + for arg in wraptuple(args) + for letter in (:x, :y, :z) + process_axis_arg!(d, arg, letter) + end + end # handle axis args for letter in (:x, :y, :z) asym = Symbol(letter, :axis) diff --git a/src/axes.jl b/src/axes.jl index 6d06a261..bf7175ed 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -70,7 +70,7 @@ function process_axis_arg!(d::KW, arg, letter = "") elseif arg == nothing d[Symbol(letter,:ticks)] = [] - elseif arg in _allShowaxisArgs + elseif T <: Bool || arg in _allShowaxisArgs d[Symbol(letter,:showaxis)] = showaxis(arg, letter) elseif typeof(arg) <: Number @@ -79,7 +79,7 @@ function process_axis_arg!(d::KW, arg, letter = "") elseif typeof(arg) <: Function d[Symbol(letter,:formatter)] = arg - else + elseif !handleColors!(d, arg, Symbol(letter, :foreground_color_axis)) warn("Skipped $(letter)axis arg $arg") end From 6d53594850bfc6ea94e1bd54e8edadf57dc83ef8 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 Sep 2017 15:09:28 +0200 Subject: [PATCH 005/115] implement showaxis for plotly --- src/backends/plotly.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 1dd9060a..b3c40158 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -234,10 +234,11 @@ function plotly_axis(axis::Axis, sp::Subplot) :gridwidth => axis[:gridlinewidth], :zeroline => framestyle == :zerolines, :zerolinecolor => rgba_string(axis[:foreground_color_axis]), - :showline => framestyle in (:box, :axes), + :showline => framestyle in (:box, :axes) && axis[:showaxis], :linecolor => rgba_string(plot_color(axis[:foreground_color_axis])), :ticks => axis[:tick_direction] == :out ? "outside" : "inside", :mirror => framestyle == :box, + :showticklabels => axis[:showaxis], ) if letter in (:x,:y) @@ -251,7 +252,7 @@ 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] = framestyle in (:zerolines, :grid) ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) + ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) # lims From 148ad8032f57f62b1b6f6bd2f63ae4a3bf806f0b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 Sep 2017 20:16:27 +0200 Subject: [PATCH 006/115] implement showaxis for pyplot --- src/backends/pyplot.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ea0ba6c7..d2146d68 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1077,6 +1077,24 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) py_set_axis_colors(sp, ax, axis) end + # showaxis + if !sp[:xaxis][:showaxis] + kw = KW() + for dir in (:top, :bottom) + ax[:spines][string(dir)][:set_visible](false) + kw[dir] = kw[Symbol(:label,dir)] = "off" + end + ax[:xaxis][:set_tick_params](; which="both", kw...) + end + if !sp[:yaxis][:showaxis] + kw = KW() + for dir in (:left, :right) + ax[:spines][string(dir)][:set_visible](false) + kw[dir] = kw[Symbol(:label,dir)] = "off" + end + ax[:yaxis][:set_tick_params](; which="both", kw...) + end + # aspect ratio aratio = sp[:aspect_ratio] if aratio != :none From 93df7f43679be2ce131129846ceec4f5461e9c46 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 1 Oct 2017 19:09:24 +0200 Subject: [PATCH 007/115] implement showaxis for glvisualize --- src/backends/glvisualize.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 1bdb79df..bbd5605a 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -732,15 +732,25 @@ 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)) && !(sp[:framestyle] == :none) + if !(xaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none) && xaxis[:showaxis] ticklabels = map(model) do m mirror = xaxis[:mirror] t, positions, offsets = draw_ticks(xaxis, xticks, true, sp[:framestyle] == :origin, ylim, m) - mirror = xaxis[:mirror] - t, positions, offsets = draw_ticks( - yaxis, yticks, false, sp[:framestyle] == :origin, xlim, m, - t, positions, offsets - ) + end + kw_args = Dict{Symbol, Any}( + :position => map(x-> x[2], ticklabels), + :offset => map(last, ticklabels), + :color => fcolor, + :relative_scale => pointsize(xaxis[:tickfont]), + :scale_primitive => false + ) + push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) + end + + if !(yaxis[:ticks] in (nothing, false, :none)) && !(sp[:framestyle] == :none) && yaxis[:showaxis] + ticklabels = map(model) do m + mirror = yaxis[:mirror] + t, positions, offsets = draw_ticks(yaxis, yticks, false, sp[:framestyle] == :origin, xlim, m) end kw_args = Dict{Symbol, Any}( :position => map(x-> x[2], ticklabels), From ff751ca423803d43a6fb2ca16e59268caaf7fa7a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 1 Oct 2017 20:29:46 +0200 Subject: [PATCH 008/115] implement showaxis and basic framestyles for pgfplots --- src/backends/pgfplots.jl | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 97d68421..153ee808 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -32,6 +32,7 @@ const _pgfplots_attr = merge_with_base_supported([ :aspect_ratio, # :match_dimensions, :tick_direction, + :framestyle, ]) const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @@ -107,6 +108,18 @@ const _pgf_annotation_halign = KW( :right => "left" ) +const _pgf_framestyles = [:box, :axes, :grid, :none] +const _pgf_framestyle_defaults = Dict(:semi => :box, :origin => :axes, :zerolines => :axes) +function pgf_framestyle(style::Symbol) + if style in _pgf_framestyles + return style + else + default_style = get(_pgf_framestyle_defaults, style, :axes) + warn("Framestyle :$style is not (yet) supported by the PGFPlots backend. :$default_style was cosen instead.") + default_style + end +end + # -------------------------------------------------------------------------------------- # takes in color,alpha, and returns color and alpha appropriate for pgf style @@ -246,6 +259,9 @@ function pgf_axis(sp::Subplot, letter) style = [] kw = KW() + # set to supported framestyle + framestyle = pgf_framestyle(sp[:framestyle]) + # axis guide kw[Symbol(letter,:label)] = axis[:guide] @@ -263,12 +279,12 @@ function pgf_axis(sp::Subplot, letter) end # ticks on or off - if axis[:ticks] in (nothing, false) + if axis[:ticks] in (nothing, false) || framestyle == :none push!(style, "$(letter)majorticks=false") end # grid on or off - if axis[:grid] + if axis[:grid] && framestyle != :none push!(style, "$(letter)majorgrids = true") end @@ -280,13 +296,29 @@ function pgf_axis(sp::Subplot, letter) kw[Symbol(letter,:max)] = lims[2] end - if !(axis[:ticks] in (nothing, false, :none)) + if !(axis[:ticks] in (nothing, false, :none)) && framestyle != :none ticks = get_ticks(axis) push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) - push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) + if axis[:showaxis] + push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) + else + push!(style, string(letter, "ticklabels = {}")) + end push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) end + # framestyle + if sp[:framestyle] == :axes + push!(style, "axis lines = left") + end + + if !axis[:showaxis] + push!(style, "separate axis lines") + end + if !axis[:showaxis] || framestyle in (:grid, :none) + push!(style, string(letter, " axis line style = {draw opacity = 0}")) + end + # return the style list and KW args style, kw end From 3d86d5f530612092a70236abb258eb9254650a6a Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 4 Oct 2017 11:38:32 +0200 Subject: [PATCH 009/115] Apply automatic limits for vectors of functions --- src/series.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/series.jl b/src/series.jl index 52b672a1..7e7729ea 100644 --- a/src/series.jl +++ b/src/series.jl @@ -371,6 +371,13 @@ end end # try some intervals over which the function may be defined +function tryrange(F::T, vec) where T <: AbstractArray + rets = [tryrange(f, vec) for f in F] # get the preferred for each + inds = indexin(rets, vec) # get the last attempt (most likely to fit all) + rets .= [tryrange(f, vec[maximum(inds):maximum(inds)]) for f in F] # ensure that all functions compute there + rets[1] +end + function tryrange(F, vec) for v in vec try @@ -379,7 +386,7 @@ function tryrange(F, vec) catch end end - error("Function not defined over the given interval, $vec") + error("$F is not a Function, or is not defined at any of the values $vec") end # # # -------------------------------------------------------------------- From 0327c9101e63848338c73c318b66bf26885c6e11 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 4 Oct 2017 11:44:20 +0200 Subject: [PATCH 010/115] slight refactor for clarity --- src/series.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/series.jl b/src/series.jl index 7e7729ea..84f3cc21 100644 --- a/src/series.jl +++ b/src/series.jl @@ -373,8 +373,8 @@ end # try some intervals over which the function may be defined function tryrange(F::T, vec) where T <: AbstractArray rets = [tryrange(f, vec) for f in F] # get the preferred for each - inds = indexin(rets, vec) # get the last attempt (most likely to fit all) - rets .= [tryrange(f, vec[maximum(inds):maximum(inds)]) for f in F] # ensure that all functions compute there + maxind = maximum(indexin(rets, vec)) # get the last attempt that succeeded (most likely to fit all) + rets .= [tryrange(f, vec[maxind:maxind]) for f in F] # ensure that all functions compute there rets[1] end From 5567038cec70f6eae82f2b9ef8bb450b7e3d5749 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 4 Oct 2017 11:47:20 +0200 Subject: [PATCH 011/115] simplify --- src/series.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/series.jl b/src/series.jl index 84f3cc21..c0d7d4c2 100644 --- a/src/series.jl +++ b/src/series.jl @@ -371,7 +371,7 @@ end end # try some intervals over which the function may be defined -function tryrange(F::T, vec) where T <: AbstractArray +function tryrange(F::AbstractArray, vec) rets = [tryrange(f, vec) for f in F] # get the preferred for each maxind = maximum(indexin(rets, vec)) # get the last attempt that succeeded (most likely to fit all) rets .= [tryrange(f, vec[maxind:maxind]) for f in F] # ensure that all functions compute there From e3b0f7cd94c89bfc75a7c1dfff993eb92c1a1ece Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 4 Oct 2017 13:40:56 +0200 Subject: [PATCH 012/115] pgfplots: remove axis arrows and implement origin and zerolines framestyles --- src/backends/pgfplots.jl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 153ee808..b54d8aa0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -108,8 +108,8 @@ const _pgf_annotation_halign = KW( :right => "left" ) -const _pgf_framestyles = [:box, :axes, :grid, :none] -const _pgf_framestyle_defaults = Dict(:semi => :box, :origin => :axes, :zerolines => :axes) +const _pgf_framestyles = [:box, :axes, :origin, :zerolines, :grid, :none] +const _pgf_framestyle_defaults = Dict(:semi => :box) function pgf_framestyle(style::Symbol) if style in _pgf_framestyles return style @@ -308,14 +308,22 @@ function pgf_axis(sp::Subplot, letter) end # framestyle - if sp[:framestyle] == :axes - push!(style, "axis lines = left") + if framestyle in (:axes, :origin) + axispos = framestyle == :axes ? "left" : "middle" + # the * after lines disables the arrows at the axes + push!(style, string("axis lines* = ", axispos)) + end + + if framestyle == :zerolines + push!(style, string("extra ", letter, " ticks = 0")) + push!(style, string("extra ", letter, " tick labels = ")) + push!(style, string("extra ", letter, " tick style = {grid = major, major grid style = {color = black, draw opacity=1.0, line width=0.5), solid}}")) end if !axis[:showaxis] push!(style, "separate axis lines") end - if !axis[:showaxis] || framestyle in (:grid, :none) + if !axis[:showaxis] || framestyle in (:zerolines, :grid, :none) push!(style, string(letter, " axis line style = {draw opacity = 0}")) end From f5ee5ea8148f92ebc8242a41b7e920f7e2933ee2 Mon Sep 17 00:00:00 2001 From: Darwin Darakananda Date: Wed, 4 Oct 2017 14:26:35 -0700 Subject: [PATCH 013/115] Fix `line_z` for PyPlot backend `LineCollection` expects an array with pairs of coordinates, corresponding to the starting and ending points of each segment. --- src/backends/pyplot.jl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ea0ba6c7..12442aec 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -508,11 +508,12 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) handle = if is3d(st) for rng in iter_segments(x, y, z) length(rng) < 2 && continue - push!(segments, [(_cycle(x,i),_cycle(y,i),_cycle(z,i)) for i in rng]) + for i in rng[1:end-1] + push!(segments, [(_cycle(x,i),_cycle(y,i),_cycle(z,i)), + (_cycle(x,i+1),_cycle(y,i+1),_cycle(z,i+1))]) + end end - # for i=1:n - # segments[i] = [(_cycle(x,i), _cycle(y,i), _cycle(z,i)), (_cycle(x,i+1), _cycle(y,i+1), _cycle(z,i+1))] - # end + lc = pyart3d["Line3DCollection"](segments; kw...) lc[:set_array](lz) ax[:add_collection3d](lc, zs=z) #, zdir='y') @@ -520,11 +521,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) else for rng in iter_segments(x, y) length(rng) < 2 && continue - push!(segments, [(_cycle(x,i),_cycle(y,i)) for i in rng]) + for i in rng[1:end-1] + push!(segments, [(_cycle(x,i),_cycle(y,i)), (_cycle(x,i+1),_cycle(y,i+1))]) + end end - # for i=1:n - # segments[i] = [(_cycle(x,i), _cycle(y,i)), (_cycle(x,i+1), _cycle(y,i+1))] - # end + lc = pycollections["LineCollection"](segments; kw...) lc[:set_array](lz) ax[:add_collection](lc) From 514cd1bd3735c63d8642a044c2a3a048c492501b Mon Sep 17 00:00:00 2001 From: Darwin Darakananda Date: Wed, 4 Oct 2017 15:10:36 -0700 Subject: [PATCH 014/115] normalize colors even when plotting without colorbars --- src/backends/pyplot.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 12442aec..9918ec08 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -499,11 +499,9 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) :zorder => plt.n, :cmap => py_linecolormap(series), :linewidth => py_dpi_scale(plt, series[:linewidth]), - :linestyle => py_linestyle(st, series[:linestyle]) + :linestyle => py_linestyle(st, series[:linestyle]), + :norm => pycolors["Normalize"](; extrakw...) ) - if needs_colorbar - kw[:norm] = pycolors["Normalize"](; extrakw...) - end lz = collect(series[:line_z]) handle = if is3d(st) for rng in iter_segments(x, y, z) From 878fa48afad20a00f7765dad1b691d20ae66627c Mon Sep 17 00:00:00 2001 From: JackDevine Date: Thu, 5 Oct 2017 21:35:38 +1300 Subject: [PATCH 015/115] PyPlot legends now show marker types. --- src/backends/pyplot.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index ea0ba6c7..26af0634 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1183,6 +1183,12 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) color = py_color(_cycle(series[:fillcolor],1)), linewidth = py_dpi_scale(plt, 4) ) + elseif series[:seriestype] == :path + PyPlot.plt[:Line2D]((0,1),(0,0), + color = py_color(_cycle(series[:fillcolor],1)), + linewidth = py_dpi_scale(plt, 1), + marker = py_marker(series[:markershape]) + ) else series[:serieshandle][1] end) From 520dc80eeb3301abeca26ae7b1200c50cb533fa9 Mon Sep 17 00:00:00 2001 From: JackDevine Date: Thu, 5 Oct 2017 22:58:18 +1300 Subject: [PATCH 016/115] Added marker strokes --- src/backends/pyplot.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 26af0634..4c9173c7 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1187,7 +1187,9 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) PyPlot.plt[:Line2D]((0,1),(0,0), color = py_color(_cycle(series[:fillcolor],1)), linewidth = py_dpi_scale(plt, 1), - marker = py_marker(series[:markershape]) + marker = py_marker(series[:markershape]), + markeredgecolor = py_markerstrokecolor(series), + markerfacecolor = py_markercolor(series) ) else series[:serieshandle][1] From b37f2141a1e7eb1bc74ff3d3403f13bd71bb3e20 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:08:15 +0200 Subject: [PATCH 017/115] Also import px and pct into PlotMeasures Necessary for example 29 to work --- src/Plots.jl | 7 +++++-- src/layouts.jl | 4 ---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e730e65c..e2ffa95c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -138,12 +138,15 @@ module PlotMeasures import Measures import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h const BBox = Measures.Absolute2DBox -export BBox, BoundingBox, mm, cm, inch, pt, px, pct, w, h + +# allow pixels and percentages +const px = AbsoluteLength(0.254) +const pct = Length{:pct, Float64}(1.0) +export BBox, BoundingBox, mm, cm, inch, px, pct, pt, w, h end using .PlotMeasures import .PlotMeasures: Length, AbsoluteLength, Measure, width, height -export BBox, BoundingBox # --------------------------------------------------------- include("types.jl") diff --git a/src/layouts.jl b/src/layouts.jl index 9e90a2f1..9bd4d3b2 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -1,10 +1,6 @@ # NOTE: (0,0) is the top-left !!! -# allow pixels and percentages -const px = AbsoluteLength(0.254) -const pct = Length{:pct, Float64}(1.0) - to_pixels(m::AbsoluteLength) = m.value / 0.254 const _cbar_width = 5mm From fdf2d5b20b90a8d697e1c2e789e132f235ed824e Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:22:12 +0200 Subject: [PATCH 018/115] ready for release --- NEWS.md | 5 +++++ src/Plots.jl | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 491b699f..6f68c1f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,11 @@ --- ## (current master) +## 0.13.1 + +- fix a bug when passing a vector of functions with no bounds (e.g. `plot([sin, cos])`) +- export pct and px from Plots.PlotMeasures + ## 0.13.0 - support `plotattributes` rather than `d` in recipes diff --git a/src/Plots.jl b/src/Plots.jl index e2ffa95c..33703c9f 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(true) +__precompile__(false) module Plots From 9fc0c98722af38909ffae8ceca600e0ee222eccd Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:25:04 +0200 Subject: [PATCH 019/115] precompile --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 33703c9f..e2ffa95c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(false) +__precompile__(true) module Plots From 77fa5454e21ac47d93852d82e6896e2aa01f88a4 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:27:51 +0200 Subject: [PATCH 020/115] remember backticks --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6f68c1f5..05f416f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,7 +14,7 @@ ## 0.13.1 - fix a bug when passing a vector of functions with no bounds (e.g. `plot([sin, cos])`) -- export pct and px from Plots.PlotMeasures +- export `pct` and `px` from Plots.PlotMeasures ## 0.13.0 From 531a38bc39a7e64ee0d8f905e7d112ae23c6d4e9 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:28:52 +0200 Subject: [PATCH 021/115] no prec --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index e2ffa95c..33703c9f 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(true) +__precompile__(false) module Plots From 78e3b69cc57b94b134b9980a2d40717e221a8683 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 12:30:29 +0200 Subject: [PATCH 022/115] prec --- src/Plots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plots.jl b/src/Plots.jl index 33703c9f..e2ffa95c 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,4 +1,4 @@ -__precompile__(false) +__precompile__(true) module Plots From 12488bf2b0cff37641055ee26a37607615ceb91e Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 5 Oct 2017 13:24:21 +0200 Subject: [PATCH 023/115] Drop tests for pyplot (temporarily) revisit 12 oct --- test/runtests.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 3f471735..4f0b2ad0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,12 +16,12 @@ img_eps = isinteractive() ? 1e-2 : 10e-2 end -@testset "PyPlot" begin - @test pyplot() == Plots.PyPlotBackend() - @test backend() == Plots.PyPlotBackend() - - image_comparison_facts(:pyplot, eps=img_eps) -end +#@testset "PyPlot" begin +# @test pyplot() == Plots.PyPlotBackend() +# @test backend() == Plots.PyPlotBackend() +# +# image_comparison_facts(:pyplot, eps=img_eps) +#end @testset "UnicodePlots" begin @test unicodeplots() == Plots.UnicodePlotsBackend() From 16d18552f85c2c45b71bd55f8524f4c05eed2bd4 Mon Sep 17 00:00:00 2001 From: Darwin Darakananda Date: Thu, 5 Oct 2017 20:49:17 -0700 Subject: [PATCH 024/115] Allow `line_z` to specify color across multiple lines --- src/backends/pyplot.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 9918ec08..c42f6547 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -502,7 +502,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) :linestyle => py_linestyle(st, series[:linestyle]), :norm => pycolors["Normalize"](; extrakw...) ) - lz = collect(series[:line_z]) + lz = _cycle(series[:line_z], 1:n) handle = if is3d(st) for rng in iter_segments(x, y, z) length(rng) < 2 && continue From 0c5a9172abf12c9d1c005e231de8540762bef263 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:03:19 +0100 Subject: [PATCH 025/115] Added camera attribute processing. --- src/arg_desc.jl | 1 + src/args.jl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index ce24b8e0..53c8b51f 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -94,6 +94,7 @@ const _arg_desc = KW( :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.", :framestyle => "Symbol. Style of the axes frame. Choose from $(_allFramestyles)", +:camera => "NTuple{2, Int(GR)/Real(Other)}. Sets the view angle (azimuthal, elevation) for 3D plots", # axis args :guide => "String. Axis guide (label).", diff --git a/src/args.jl b/src/args.jl index 3ea3efde..f36f2908 100644 --- a/src/args.jl +++ b/src/args.jl @@ -316,6 +316,7 @@ const _subplot_defaults = KW( :subplot_index => -1, :colorbar_title => "", :framestyle => :axes, + :camera => (30,30), ) const _axis_defaults = KW( @@ -532,6 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) +add_aliases(:camera, :cam) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From 65a28e76e548e16938b3eb9f2602afb6b21cef6d Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:06:39 +0100 Subject: [PATCH 026/115] Implemented camera attribute for GR. --- src/backends/gr.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 0d1d5a21..21d2c5db 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -34,6 +34,7 @@ const _gr_attr = merge_with_base_supported([ :arrow, :framestyle, :tick_direction, + :camera, ]) const _gr_seriestype = [ :path, :scatter, @@ -750,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, 35, 60) + GR.setspace(zmin, zmax, sp[:camera]...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2 From 94e79f1e4cfef52da891e8bc3d592ac28b14ba6b Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:07:31 +0100 Subject: [PATCH 027/115] Implemented camera attribute for PyPlot. --- src/backends/pyplot.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 6ad195a2..e3b70eb9 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -35,6 +35,7 @@ const _pyplot_attr = merge_with_base_supported([ :stride, :framestyle, :tick_direction, + :camera, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, @@ -1104,6 +1105,13 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) ax[:set_aspect](isa(aratio, Symbol) ? string(aratio) : aratio, anchor = "C") end + #camera/view angle + if is3d(sp) + #convert azimuthal to match GR behaviour + #view_init(elevation, azimuthal) so reverse :camera args + ax[:view_init]((sp[:camera].-(90,0))[end:-1:1]...) + end + # legend py_add_legend(plt, sp, ax) From 0fb1a0ed6bfc579f7577aae59de59819bac8e104 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:07:48 +0100 Subject: [PATCH 028/115] Implemented camera attribute for PGFPlots. --- src/backends/pgfplots.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index b54d8aa0..a5f1a1b0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -33,6 +33,7 @@ const _pgfplots_attr = merge_with_base_supported([ # :match_dimensions, :tick_direction, :framestyle, + :camera, ]) const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @@ -380,6 +381,11 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) kw[:legendPos] = _pgfplots_legend_pos[legpos] end + if is3d(sp) + azim, elev = sp[:camera] + kw[:view] = "{$(azim)}{$(elev)}" + end + axisf = PGFPlots.Axis if sp[:projection] == :polar axisf = PGFPlots.PolarAxis From ccb3cadd2a9e9fa7a9d372bbf21c79542bcc916c Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 6 Oct 2017 20:09:39 +0100 Subject: [PATCH 029/115] Implemented camera attribute for Plotly/PlotlyJS. --- src/backends/plotly.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b3c40158..c67511d2 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -35,6 +35,7 @@ const _plotly_attr = merge_with_base_supported([ :clims, :framestyle, :tick_direction, + :camera, ]) const _plotly_seriestype = [ @@ -324,10 +325,21 @@ function plotly_layout(plt::Plot) # if any(is3d, seriesargs) if is3d(sp) + azim = sp[:camera][1] - 90 #convert azimuthal to match GR behaviour + theta = 90 - sp[:camera][2] #spherical coordinate angle from z axis d_out[:scene] = KW( Symbol("xaxis$spidx") => plotly_axis(sp[:xaxis], sp), Symbol("yaxis$spidx") => plotly_axis(sp[:yaxis], sp), Symbol("zaxis$spidx") => plotly_axis(sp[:zaxis], sp), + + #2.6 multiplier set camera eye such that whole plot can be seen + :camera => KW( + :eye => KW( + :x => cosd(azim)*sind(theta)*2.6, + :y => sind(azim)*sind(theta)*2.6, + :z => cosd(theta)*2.6, + ), + ), ) else d_out[Symbol("xaxis$spidx")] = plotly_axis(sp[:xaxis], sp) From cb7498a30d023465969aff505899f55a67da9761 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 7 Oct 2017 21:02:14 +0200 Subject: [PATCH 030/115] fix linestyle on gr --- src/backends/gr.jl | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 0d1d5a21..d78aa804 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -943,16 +943,22 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if st in (:path, :scatter) if length(x) > 1 + lz = series[:line_z] + segments_iterator = if lz != nothing && length(lz) > 1 + [i:(i + 1) for i in 1:(length(x) - 1)] + else + iter_segments(x, y) + end # do area fill if frng != nothing GR.setfillintstyle(GR.INTSTYLE_SOLID) fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng)) - for i in 1:length(x) - 1 + for (i, rng) in enumerate(segments_iterator) gr_set_fillcolor(get_fillcolor(sp, series, i)) - xseg = _cycle(x, [i, i+1, i+1, i]) - yseg = [_cycle(fr_from, [i, i+1]); _cycle(fr_to, [i+1, i])] + fx = _cycle(x, vcat(rng, reverse(rng))) + fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng))) series[:fillalpha] != nothing && GR.settransparency(series[:fillalpha]) - GR.fillarea(xseg, yseg) + GR.fillarea(fx, fy) end gr_set_line(1, :solid, yaxis[:foreground_color_axis]) GR.settransparency(1) @@ -961,12 +967,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # draw the line(s) if st == :path - for i in 1:length(x) - 1 - xseg = x[i:(i + 1)] - yseg = y[i:(i + 1)] + for (i, rng) in enumerate(segments_iterator) gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) - arrowside = (i == length(y) - 1) && isa(series[:arrow], Arrow) ? series[:arrow].side : :none - gr_polyline(xseg, yseg; arrowside = arrowside) + arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none + gr_polyline(x[rng], y[rng]; arrowside = arrowside) end gr_set_line(1, :solid, yaxis[:foreground_color_axis]) cmap && gr_colorbar(sp, clims) @@ -1036,15 +1040,20 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif st in (:path3d, :scatter3d) # draw path if st == :path3d - for i in 1:length(x) - 1 - xseg = x[i:(i + 1)] - yseg = y[i:(i + 1)] - zseg = z[i:(i + 1)] - gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) - GR.polyline3d(xseg, yseg, zseg) + if length(x) > 1 + lz = series[:line_z] + segments_iterator = if lz != nothing && length(lz) > 1 + [i:(i + 1) for i in 1:(length(x) - 1)] + else + iter_segments(x, y, z) + end + for (i, rng) in enumerate(segments_iterator) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) + GR.polyline3d(x[rng], y[rng], z[rng]) + end + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + cmap && gr_colorbar(sp, clims) end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - cmap && gr_colorbar(sp, clims) end # draw markers From cf6f7035b6d9badc5e879ecf2c27d8a5dcd42d08 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 7 Oct 2017 20:05:05 +0100 Subject: [PATCH 031/115] Added extra :camera aliases. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index f36f2908..505b1d74 100644 --- a/src/args.jl +++ b/src/args.jl @@ -533,7 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) -add_aliases(:camera, :cam) +add_aliases(:camera, :cam, :view, :viewangle, :view_angle) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From f4bc2e06490fadb5bc5957af3bc85bc05fdc87ff Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 7 Oct 2017 20:05:53 +0100 Subject: [PATCH 032/115] Convert :camera attribute input for GR. --- src/arg_desc.jl | 2 +- src/backends/gr.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 53c8b51f..f0df3e92 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -94,7 +94,7 @@ const _arg_desc = KW( :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.", :framestyle => "Symbol. Style of the axes frame. Choose from $(_allFramestyles)", -:camera => "NTuple{2, Int(GR)/Real(Other)}. Sets the view angle (azimuthal, elevation) for 3D plots", +:camera => "NTuple{2, Real}. Sets the view angle (azimuthal, elevation) for 3D plots", # axis args :guide => "String. Axis guide (label).", diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 21d2c5db..01b9d6e6 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -751,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, sp[:camera]...) + GR.setspace(zmin, zmax, map(Int,map(round,sp[:camera]))...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2 From a016b655f47a8d8d09ffba77b9f2fa5e9720acc8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 7 Oct 2017 13:06:08 -0700 Subject: [PATCH 033/115] New docs page link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72a82007..c107eaab 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ Plots is a plotting API and toolset. My goals with the package are: - **Lightweight**. Very few dependencies. - **Smart**. Attempts to figure out what you **want** it to do... not just what you **tell** it. -View the [full documentation](http://juliaplots.github.io). +View the [full documentation](docs.juliaplots.org/latest). From eda1ebe36becb9d9b3f4ce8565b65635ca945ab7 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 7 Oct 2017 13:24:03 -0700 Subject: [PATCH 034/115] Fix docs link Ugh, flubbed that one. There's the `http://` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c107eaab..ebafb2db 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ Plots is a plotting API and toolset. My goals with the package are: - **Lightweight**. Very few dependencies. - **Smart**. Attempts to figure out what you **want** it to do... not just what you **tell** it. -View the [full documentation](docs.juliaplots.org/latest). +View the [full documentation](http://docs.juliaplots.org/latest). From f8576c71350ccc43fb36cdbbfd431c37d2ff4973 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Mon, 9 Oct 2017 11:33:24 +0100 Subject: [PATCH 035/115] Remove :view alias for :camera attribute. --- src/args.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 505b1d74..7632b5bf 100644 --- a/src/args.jl +++ b/src/args.jl @@ -533,7 +533,7 @@ add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, : add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) -add_aliases(:camera, :cam, :view, :viewangle, :view_angle) +add_aliases(:camera, :cam, :viewangle, :view_angle) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) From 6df2bc2790c8018db6eaf731ef08654199c29d64 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Mon, 9 Oct 2017 11:40:04 +0100 Subject: [PATCH 036/115] Clarify gr.jl setspace() rounding syntax. --- 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 01b9d6e6..5430f53b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -751,7 +751,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) isfinite(clims[1]) && (zmin = clims[1]) isfinite(clims[2]) && (zmax = clims[2]) end - GR.setspace(zmin, zmax, map(Int,map(round,sp[:camera]))...) + GR.setspace(zmin, zmax, round.(Int, sp[:camera])...) xtick = GR.tick(xmin, xmax) / 2 ytick = GR.tick(ymin, ymax) / 2 ztick = GR.tick(zmin, zmax) / 2 From 55c968f1389fb9173ac62aa687f1b59a67fabbd5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 9 Oct 2017 17:13:44 +0200 Subject: [PATCH 037/115] fix marker_z for 3D plots - draw colorbar once per series --- src/backends/gr.jl | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d78aa804..6d41c547 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -342,10 +342,10 @@ function gr_draw_markers(series::Series, x, y, clims) mz = normalize_zvals(series[:marker_z], clims) GR.setfillintstyle(GR.INTSTYLE_SOLID) gr_draw_markers(series, x, y, series[:markersize], mz) - if hascolorbar(series[:subplot]) - GR.setscale(0) - gr_colorbar(series[:subplot], clims) - end + # if hascolorbar(series[:subplot]) + # GR.setscale(0) + # gr_colorbar(series[:subplot], clims) + # end end # --------------------------------------------------------- @@ -960,9 +960,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) series[:fillalpha] != nothing && GR.settransparency(series[:fillalpha]) GR.fillarea(fx, fy) end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - GR.settransparency(1) - cmap && gr_colorbar(sp, clims) end # draw the line(s) @@ -972,8 +969,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none gr_polyline(x[rng], y[rng]; arrowside = arrowside) end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - cmap && gr_colorbar(sp, clims) end end @@ -1021,7 +1016,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setfillcolorind(0) GR.surface(x, y, z, GR.OPTION_FILLED_MESH) end - cmap && gr_colorbar(sp) elseif st == :heatmap xmin, xmax, ymin, ymax = xy_lims @@ -1035,7 +1029,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) round(Int, red(c) * 255) ), colors) w, h = length(x), length(y) GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba) - cmap && gr_colorbar(sp, clims) elseif st in (:path3d, :scatter3d) # draw path @@ -1051,8 +1044,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) GR.polyline3d(x[rng], y[rng], z[rng]) end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - cmap && gr_colorbar(sp, clims) end end @@ -1128,8 +1119,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.polyline(xseg, yseg) end end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - cmap && gr_colorbar(sp, clims) elseif st == :image @@ -1147,6 +1136,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba) end + # draw the colorbar + if cmap && st != :contour # special colorbar with steps is drawn for contours + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + GR.settransparency(1) + gr_colorbar(sp, clims) + end + # this is all we need to add the series_annotations text anns = series[:series_annotations] for (xi,yi,str,fnt) in EachAnn(anns, x, y) From bac192d825ffd9b4dd21e8ccf3da268e02f5da58 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 9 Oct 2017 17:20:36 +0200 Subject: [PATCH 038/115] remove unnecessary lines --- src/backends/gr.jl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 6d41c547..d90aedf4 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -342,10 +342,6 @@ function gr_draw_markers(series::Series, x, y, clims) mz = normalize_zvals(series[:marker_z], clims) GR.setfillintstyle(GR.INTSTYLE_SOLID) gr_draw_markers(series, x, y, series[:markersize], mz) - # if hascolorbar(series[:subplot]) - # GR.setscale(0) - # gr_colorbar(series[:subplot], clims) - # end end # --------------------------------------------------------- @@ -447,12 +443,6 @@ function gr_set_viewport_polar() end # add the colorbar -function gr_colorbar(sp::Subplot) - gr_set_viewport_cmap(sp) - GR.colorbar() - gr_set_viewport_plotarea() -end - function gr_colorbar(sp::Subplot, clims) xmin, xmax = gr_xy_axislims(sp)[1:2] gr_set_viewport_cmap(sp) From 08bdd11410955d56e4020480047854681aa1f7f3 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 9 Oct 2017 21:19:32 +0200 Subject: [PATCH 039/115] New spy implementation --- src/recipes.jl | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 109b7b05..97352505 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -945,23 +945,21 @@ end @recipe function f(::Type{Val{:spy}}, x,y,z) yflip := true aspect_ratio := 1 + rs, cs, zs = findnz(z.surf) - xlim := ignorenan_extrema(cs) - ylim := ignorenan_extrema(rs) - if plotattributes[:markershape] == :none - markershape := :circle + newz = fill(NaN, size(z)...) + + for i in eachindex(zs) + newz[rs[i],cs[i]] = zs[i] end - if plotattributes[:markersize] == default(:markersize) - markersize := 1 - end - markerstrokewidth := 0 - marker_z := zs - label := "" - x := cs - y := rs - z := nothing - seriestype := :scatter + + seriestype := :heatmap grid --> false + framestyle --> :box + + x := x + y := y + z := Surface(newz) () end From cc201ce4e7d760cb2526ecb20b4b291d81fb53df Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Tue, 10 Oct 2017 10:54:29 +0200 Subject: [PATCH 040/115] gr: fixed colorbar problem for flipped axes --- src/backends/gr.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index d78aa804..898729f6 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -458,6 +458,7 @@ function gr_colorbar(sp::Subplot, clims) gr_set_viewport_cmap(sp) l = zeros(Int32, 1, 256) l[1,:] = Int[round(Int, _i) for _i in linspace(1000, 1255, 256)] + GR.setscale(0) GR.setwindow(xmin, xmax, clims[1], clims[2]) GR.cellarray(xmin, xmax, clims[2], clims[1], 1, length(l), l) ztick = 0.5 * GR.tick(clims[1], clims[2]) From 9dcbc06b3d688e3a5fc8c3e4dbc38104f686ee00 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 10 Oct 2017 19:50:45 +0200 Subject: [PATCH 041/115] update version for tests --- test/imgcomp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/imgcomp.jl b/test/imgcomp.jl index d59aa5fa..b9038d3d 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.4" +const _current_plots_version = v"0.13.1" function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], eps = 1e-2) From 979a846298114e9b5449b4481acab89b440678ff Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 10 Oct 2017 23:26:39 +0200 Subject: [PATCH 042/115] fix flip for GR --- src/axes.jl | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 6b437f22..2ba6b0ce 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -518,12 +518,16 @@ function axis_drawing_info(sp::Subplot) xborder_segs = Segments(2) yborder_segs = Segments(2) - if !(sp[:framestyle] == :none) + if sp[:framestyle] != :none # xaxis if xaxis[:showaxis] - sp[:framestyle] in (:grid, :origin, :zerolines) || push!(xaxis_segs, (xmin,ymin), (xmax,ymin)) # bottom spine / xaxis - if sp[:framestyle] in (:origin, :zerolines) - push!(xaxis_segs, (xmin, 0.0), (xmax, 0.0)) + if sp[:framestyle] != :grid + yval = if sp[:framestyle] in (:origin, :zerolines) + 0.0 + else + xor(xaxis[:mirror], yaxis[:flip]) ? ymax : ymin + end + push!(xaxis_segs, (xmin, yval), (xmax, yval)) # don't show the 0 tick label for the origin framestyle if sp[:framestyle] == :origin && length(xticks) > 1 showticks = xticks[1] .!= 0 @@ -545,7 +549,7 @@ function axis_drawing_info(sp::Subplot) tick_start, tick_stop = if sp[:framestyle] == :origin (0, t3) else - xaxis[:mirror] ? (ymax, t2) : (ymin, t1) + xor(xaxis[:mirror], yaxis[:flip]) ? (ymax, t2) : (ymin, t1) end push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick end @@ -556,9 +560,13 @@ function axis_drawing_info(sp::Subplot) # yaxis if yaxis[:showaxis] - sp[:framestyle] in (:grid, :origin, :zerolines) || push!(yaxis_segs, (xmin,ymin), (xmin,ymax)) # left spine / yaxis - if sp[:framestyle] in (:origin, :zerolines) - push!(yaxis_segs, (0.0, ymin), (0.0, ymax)) + if sp[:framestyle] != :grid + xval = if sp[:framestyle] in (:origin, :zerolines) + 0.0 + else + xor(yaxis[:mirror], xaxis[:flip]) ? xmax : xmin + end + push!(yaxis_segs, (xval, ymin), (xval, ymax)) # don't show the 0 tick label for the origin framestyle if sp[:framestyle] == :origin && length(yticks) > 1 showticks = yticks[1] .!= 0 @@ -580,7 +588,7 @@ function axis_drawing_info(sp::Subplot) tick_start, tick_stop = if sp[:framestyle] == :origin (0, t3) else - yaxis[:mirror] ? (xmax, t2) : (xmin, t1) + xor(yaxis[:mirror], xaxis[:flip]) ? (xmax, t2) : (xmin, t1) end push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick end From be55c1ad6f57c1e7ac150e40501e680fbd3149d1 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Tue, 10 Oct 2017 23:29:18 +0100 Subject: [PATCH 043/115] save svg plotlyjs --- src/backends/plotlyjs.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 0a2ad219..0776dbf1 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -85,7 +85,8 @@ end # ---------------------------------------------------------------- -function _show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) +function Base.show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend}) + prepare_output(plt) if isijulia() && !_use_remote[] write(io, PlotlyJS.html_body(PlotlyJS.JupyterPlot(plt.o))) else @@ -98,6 +99,7 @@ function plotlyjs_save_hack(io::IO, plt::Plot{PlotlyJSBackend}, ext::String) PlotlyJS.savefig(plt.o, tmpfn) write(io, read(open(tmpfn))) end +_show(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "svg") _show(io::IO, ::MIME"image/png", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "png") _show(io::IO, ::MIME"application/pdf", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "pdf") _show(io::IO, ::MIME"image/eps", plt::Plot{PlotlyJSBackend}) = plotlyjs_save_hack(io, plt, "eps") From 4c7ab232d56fbe98c62fed6f15f191d72b1d6ec3 Mon Sep 17 00:00:00 2001 From: Darwin Darakananda Date: Wed, 11 Oct 2017 10:25:54 -0700 Subject: [PATCH 044/115] Add (back?) ability to reset defaults --- src/args.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/args.jl b/src/args.jl index 3ea3efde..b7f0d278 100644 --- a/src/args.jl +++ b/src/args.jl @@ -393,6 +393,8 @@ const _all_defaults = KW[ _axis_defaults_byletter ] +const _initial_defaults = deepcopy(_all_defaults) + # to be able to reset font sizes to initial values const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefont].pointsize, :legendfont => _subplot_defaults[:legendfont].pointsize, @@ -588,6 +590,7 @@ function default(d::KW, k::Symbol) get(d, k, default(k)) end +reset_defaults() = foreach(merge!, _all_defaults, _initial_defaults) # ----------------------------------------------------------------------------- From 422988b3f6f005c178ed2530d6b4612ab9990b5c Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Fri, 13 Oct 2017 12:38:56 +0200 Subject: [PATCH 045/115] fix `weights` in `histogram` --- src/recipes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recipes.jl b/src/recipes.jl index 97352505..8fb582ae 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -550,7 +550,7 @@ function _make_hist{N}(vs::NTuple{N,AbstractVector}, binning; normed = false, we edges = _hist_edges(vs, binning) h = float( weights == nothing ? StatsBase.fit(StatsBase.Histogram, vs, edges, closed = :left) : - StatsBase.fit(StatsBase.Histogram, vs, weights, edges, closed = :left) + StatsBase.fit(StatsBase.Histogram, vs, StatsBase.Weights(weights), edges, closed = :left) ) normalize!(h, mode = _hist_norm_mode(normed)) end From 6db7116db9f4b8a56f00950a97add4590882d47f Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Fri, 13 Oct 2017 17:08:26 +0200 Subject: [PATCH 046/115] add `weights` argument to histogram example --- src/examples.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples.jl b/src/examples.jl index fabb368d..ed62e00e 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -145,7 +145,7 @@ PlotExample("Bar", PlotExample("Histogram", "", [:(begin - histogram(randn(1000), nbins=20) + histogram(randn(1000), bins = :scott, weights = repeat(1:5, outer = 200)) end)] ), From d8ba26f79074a6b927ea94e0b06d6c98712d51ef Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Sat, 14 Oct 2017 08:52:51 +0200 Subject: [PATCH 047/115] Don't copy input arguments into `d` --- src/series.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/series.jl b/src/series.jl index c0d7d4c2..5ad05fe5 100644 --- a/src/series.jl +++ b/src/series.jl @@ -75,17 +75,17 @@ end compute_x(x::Void, y::Void, z) = 1:size(z,1) compute_x(x::Void, y, z) = 1:size(y,1) compute_x(x::Function, y, z) = map(x, y) -compute_x(x, y, z) = copy(x) +compute_x(x, y, z) = x # compute_y(x::Void, y::Function, z) = error() compute_y(x::Void, y::Void, z) = 1:size(z,2) compute_y(x, y::Function, z) = map(y, x) -compute_y(x, y, z) = copy(y) +compute_y(x, y, z) = y compute_z(x, y, z::Function) = map(z, x, y) compute_z(x, y, z::AbstractMatrix) = Surface(z) compute_z(x, y, z::Void) = nothing -compute_z(x, y, z) = copy(z) +compute_z(x, y, z) = z nobigs(v::AVec{BigFloat}) = map(Float64, v) nobigs(v::AVec{BigInt}) = map(Int64, v) @@ -371,7 +371,7 @@ end end # try some intervals over which the function may be defined -function tryrange(F::AbstractArray, vec) +function tryrange(F::AbstractArray, vec) rets = [tryrange(f, vec) for f in F] # get the preferred for each maxind = maximum(indexin(rets, vec)) # get the last attempt that succeeded (most likely to fit all) rets .= [tryrange(f, vec[maxind:maxind]) for f in F] # ensure that all functions compute there From 735a45b4e96879c3ad5d498b2a9c2756c3e49e7e Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Sat, 14 Oct 2017 22:55:23 +0200 Subject: [PATCH 048/115] Revert "Don't copy input arguments - fix #1175" --- src/series.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/series.jl b/src/series.jl index 5ad05fe5..c0d7d4c2 100644 --- a/src/series.jl +++ b/src/series.jl @@ -75,17 +75,17 @@ end compute_x(x::Void, y::Void, z) = 1:size(z,1) compute_x(x::Void, y, z) = 1:size(y,1) compute_x(x::Function, y, z) = map(x, y) -compute_x(x, y, z) = x +compute_x(x, y, z) = copy(x) # compute_y(x::Void, y::Function, z) = error() compute_y(x::Void, y::Void, z) = 1:size(z,2) compute_y(x, y::Function, z) = map(y, x) -compute_y(x, y, z) = y +compute_y(x, y, z) = copy(y) compute_z(x, y, z::Function) = map(z, x, y) compute_z(x, y, z::AbstractMatrix) = Surface(z) compute_z(x, y, z::Void) = nothing -compute_z(x, y, z) = z +compute_z(x, y, z) = copy(z) nobigs(v::AVec{BigFloat}) = map(Float64, v) nobigs(v::AVec{BigInt}) = map(Int64, v) @@ -371,7 +371,7 @@ end end # try some intervals over which the function may be defined -function tryrange(F::AbstractArray, vec) +function tryrange(F::AbstractArray, vec) rets = [tryrange(f, vec) for f in F] # get the preferred for each maxind = maximum(indexin(rets, vec)) # get the last attempt that succeeded (most likely to fit all) rets .= [tryrange(f, vec[maxind:maxind]) for f in F] # ensure that all functions compute there From 8ea878a2a2ca67ad45002979fa0423ad921b0b77 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Sun, 15 Oct 2017 12:43:15 +0200 Subject: [PATCH 049/115] Fix appveyor badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebafb2db..16f70198 100644 --- a/README.md +++ b/README.md @@ -1,7 +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) +[![Build status](https://ci.appveyor.com/api/projects/status/github/juliaplots/plots.jl?branch=master&svg=true)](https://ci.appveyor.com/project/mkborregaard/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 94c0957e11f3101c7af8881be70382cf35f1ce69 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 16 Oct 2017 18:04:46 +0200 Subject: [PATCH 050/115] draw colorbar in the end --- src/backends/gr.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9d9d6b32..96ca08f4 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1128,13 +1128,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba) end - # draw the colorbar - if cmap && st != :contour # special colorbar with steps is drawn for contours - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - GR.settransparency(1) - gr_colorbar(sp, clims) - end - # this is all we need to add the series_annotations text anns = series[:series_annotations] for (xi,yi,str,fnt) in EachAnn(anns, x, y) @@ -1142,6 +1135,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_text(GR.wctondc(xi, yi)..., str) end + # draw the colorbar + if cmap && st != :contour # special colorbar with steps is drawn for contours + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + GR.settransparency(1) + gr_colorbar(sp, clims) + end + GR.restorestate() end From 3ce71999e257cde2f9f24746323a2ddc00ab7c18 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 16 Oct 2017 21:24:13 +0200 Subject: [PATCH 051/115] spy recipe: change default color for matrices with unique values --- src/recipes.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/recipes.jl b/src/recipes.jl index 8fb582ae..5501351a 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -937,6 +937,8 @@ end mat = g.args[1] if length(unique(mat[mat .!= 0])) < 2 legend --> nothing + # revert the default gradient to have a darker (almost black) color in the default theme + seriescolor --> cgrad([cgrad()[0], cgrad()[1]]) end n,m = size(mat) Plots.SliceIt, 1:m, 1:n, Surface(mat) @@ -945,7 +947,7 @@ end @recipe function f(::Type{Val{:spy}}, x,y,z) yflip := true aspect_ratio := 1 - + rs, cs, zs = findnz(z.surf) newz = fill(NaN, size(z)...) From 2464d7bd9a9df7961599dc3e1c66bdaff404d14b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 16 Oct 2017 21:46:23 +0200 Subject: [PATCH 052/115] fix combination of box framestyle and flip on gr --- src/axes.jl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 2ba6b0ce..25e45694 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -522,19 +522,19 @@ function axis_drawing_info(sp::Subplot) # xaxis if xaxis[:showaxis] if sp[:framestyle] != :grid - yval = if sp[:framestyle] in (:origin, :zerolines) - 0.0 + y1, y2 = if sp[:framestyle] in (:origin, :zerolines) + 0.0, 0.0 else - xor(xaxis[:mirror], yaxis[:flip]) ? ymax : ymin + xor(xaxis[:mirror], yaxis[:flip]) ? (ymax, ymin) : (ymin, ymax) end - push!(xaxis_segs, (xmin, yval), (xmax, yval)) + push!(xaxis_segs, (xmin, y1), (xmax, y1)) # don't show the 0 tick label for the origin framestyle if sp[:framestyle] == :origin && length(xticks) > 1 showticks = xticks[1] .!= 0 xticks = (xticks[1][showticks], xticks[2][showticks]) end end - sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin,ymax), (xmax,ymax)) # top spine + sp[:framestyle] in (:semi, :box) && push!(xborder_segs, (xmin, y2), (xmax, y2)) # top spine end if !(xaxis[:ticks] in (nothing, false)) f = scalefunc(yaxis[:scale]) @@ -561,19 +561,19 @@ function axis_drawing_info(sp::Subplot) # yaxis if yaxis[:showaxis] if sp[:framestyle] != :grid - xval = if sp[:framestyle] in (:origin, :zerolines) - 0.0 + x1, x2 = if sp[:framestyle] in (:origin, :zerolines) + 0.0, 0.0 else - xor(yaxis[:mirror], xaxis[:flip]) ? xmax : xmin + xor(yaxis[:mirror], xaxis[:flip]) ? (xmax, xmin) : (xmin, xmax) end - push!(yaxis_segs, (xval, ymin), (xval, ymax)) + push!(yaxis_segs, (x1, ymin), (x1, ymax)) # don't show the 0 tick label for the origin framestyle if sp[:framestyle] == :origin && length(yticks) > 1 showticks = yticks[1] .!= 0 yticks = (yticks[1][showticks], yticks[2][showticks]) end end - sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (xmax,ymin), (xmax,ymax)) # right spine + sp[:framestyle] in (:semi, :box) && push!(yborder_segs, (x2, ymin), (x2, ymax)) # right spine end if !(yaxis[:ticks] in (nothing, false)) f = scalefunc(xaxis[:scale]) From 7f7b543e1802aa85a4bc9c1069d9b9f0a00b5340 Mon Sep 17 00:00:00 2001 From: HMH Date: Mon, 16 Oct 2017 23:53:00 +0200 Subject: [PATCH 053/115] Use ffmpeg & palette to create gifs, closes #1050 First let ffmpeg generate a colorpalette so it uses the limited amount of colors available properly and only then create the actual gif using the generated palette. This replaces convert completely as it yields far worse results for long gifs and is considerably slower. --- src/animation.jl | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 4afa01cf..9e676f7c 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -64,35 +64,15 @@ gif(anim::Animation, fn = giffn(); kw...) = buildanimation(anim.dir, fn; kw...) mov(anim::Animation, fn = movfn(); kw...) = buildanimation(anim.dir, fn; kw...) mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim.dir, fn; kw...) -const _imagemagick_initialized = Ref(false) function buildanimation(animdir::AbstractString, fn::AbstractString; fps::Integer = 20, loop::Integer = 0) fn = abspath(fn) - try - if !_imagemagick_initialized[] - file = joinpath(Pkg.dir("ImageMagick"), "deps","deps.jl") - if isfile(file) && !haskey(ENV, "MAGICK_CONFIGURE_PATH") - include(file) - end - _imagemagick_initialized[] = true - end - # prefix = get(ENV, "MAGICK_CONFIGURE_PATH", "") - # high quality - speed = round(Int, 100 / fps) - run(`convert -delay $speed -loop $loop $(joinpath(animdir, "*.png")) -alpha off $fn`) - - 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. - Will try ffmpeg, but it's lower quality...)""") - - # low quality - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -y $fn`) - # run(`ffmpeg -v warning -i "fps=$fps,scale=320:-1:flags=lanczos"`) - end + # generate a colorpalette first so ffmpeg does not have to guess it + run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.png`) + # then apply the palette to get better results + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.png -lavfi paletteuse -y $fn`) info("Saved animation to ", fn) AnimatedGif(fn) From ef29b4a5b025d23bb232f85799a3811ed301ef8d Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Tue, 17 Oct 2017 09:59:09 +0000 Subject: [PATCH 054/115] Fix deprecations --- src/Plots.jl | 48 +++++++------- src/animation.jl | 8 +-- src/args.jl | 6 +- src/axes.jl | 4 +- src/backends.jl | 6 +- src/backends/glvisualize.jl | 22 +++---- src/backends/gr.jl | 2 +- src/backends/hdf5.jl | 16 ++--- src/backends/inspectdr.jl | 12 ++-- src/backends/plotly.jl | 4 +- src/components.jl | 46 ++++++------- src/deprecated/backends/gadfly.jl | 8 +-- src/deprecated/backends/gadfly_shapes.jl | 2 +- src/deprecated/backends/immerse.jl | 4 +- src/deprecated/backends/qwt.jl | 4 +- src/deprecated/backends/winston.jl | 2 +- src/deprecated/colors.jl | 24 +++---- src/deprecated/series_args.jl | 10 +-- src/examples.jl | 2 +- src/layouts.jl | 14 ++-- src/output.jl | 6 +- src/pipeline.jl | 2 +- src/plot.jl | 2 +- src/recipes.jl | 40 ++++++------ src/series.jl | 60 ++++++++--------- src/subplots.jl | 2 +- src/types.jl | 16 ++--- src/utils.jl | 82 ++++++++++++------------ 28 files changed, 227 insertions(+), 227 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index e2ffa95c..d4f05cc5 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -110,13 +110,13 @@ export # --------------------------------------------------------- import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 -ignorenan_minimum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.minimum(x) +ignorenan_minimum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.minimum(x) ignorenan_minimum(x) = Base.minimum(x) -ignorenan_maximum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.maximum(x) +ignorenan_maximum(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.maximum(x) ignorenan_maximum(x) = Base.maximum(x) -ignorenan_mean{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.mean(x) +ignorenan_mean(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.mean(x) ignorenan_mean(x) = Base.mean(x) -ignorenan_extrema{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.extrema(x) +ignorenan_extrema(x::AbstractArray{F}) where {F<:AbstractFloat} = NaNMath.extrema(x) ignorenan_extrema(x) = Base.extrema(x) # --------------------------------------------------------- @@ -215,13 +215,13 @@ xlabel!(s::AbstractString; kw...) = plot!(; xlabel = s, kw...) 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...) +xlims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(; xlims = lims, kw...) "Set ylims for an existing plot" -ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; ylims = lims, kw...) +ylims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(; ylims = lims, kw...) "Set zlims for an existing plot" -zlims!{T<:Real,S<:Real}(lims::Tuple{T,S}; kw...) = plot!(; zlims = lims, kw...) +zlims!(lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = 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...) @@ -229,19 +229,19 @@ zlims!(zmin::Real, zmax::Real; kw...) = plot!(; zlims = (zmi "Set xticks for an existing plot" -xticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; xticks = v, kw...) +xticks!(v::AVec{T}; kw...) where {T<:Real} = plot!(; xticks = v, kw...) "Set yticks for an existing plot" -yticks!{T<:Real}(v::AVec{T}; kw...) = plot!(; yticks = v, kw...) +yticks!(v::AVec{T}; kw...) where {T<:Real} = 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...) +xticks!( +ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(; xticks = (ticks,labels), kw...) +yticks!( +ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = 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...) +annotate!(anns::AVec{T}; kw...) where {T<:Tuple} = plot!(; annotation = anns, kw...) "Flip the current plots' x axis" xflip!(flip::Bool = true; kw...) = plot!(; xflip = flip, kw...) @@ -261,22 +261,22 @@ let PlotOrSubplot = Union{Plot, Subplot} title!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; title = s, kw...) xlabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; xlabel = s, kw...) ylabel!(plt::PlotOrSubplot, s::AbstractString; kw...) = plot!(plt; ylabel = s, kw...) - xlims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; xlims = lims, kw...) - ylims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; ylims = lims, kw...) - zlims!{T<:Real,S<:Real}(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) = plot!(plt; zlims = lims, kw...) + xlims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; xlims = lims, kw...) + ylims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; ylims = lims, kw...) + zlims!(plt::PlotOrSubplot, lims::Tuple{T,S}; kw...) where {T<:Real,S<:Real} = plot!(plt; zlims = lims, kw...) xlims!(plt::PlotOrSubplot, xmin::Real, xmax::Real; kw...) = plot!(plt; xlims = (xmin,xmax), kw...) ylims!(plt::PlotOrSubplot, ymin::Real, ymax::Real; kw...) = plot!(plt; ylims = (ymin,ymax), kw...) zlims!(plt::PlotOrSubplot, zmin::Real, zmax::Real; kw...) = plot!(plt; zlims = (zmin,zmax), kw...) - xticks!{T<:Real}(plt::PlotOrSubplot, ticks::AVec{T}; kw...) = plot!(plt; xticks = ticks, kw...) - yticks!{T<:Real}(plt::PlotOrSubplot, ticks::AVec{T}; kw...) = plot!(plt; yticks = ticks, kw...) - xticks!{T<:Real,S<:AbstractString}(plt::PlotOrSubplot, - 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...) + xticks!(plt::PlotOrSubplot, ticks::AVec{T}; kw...) where {T<:Real} = plot!(plt; xticks = ticks, kw...) + yticks!(plt::PlotOrSubplot, ticks::AVec{T}; kw...) where {T<:Real} = plot!(plt; yticks = ticks, kw...) + xticks!(plt::PlotOrSubplot, + ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(plt; xticks = (ticks,labels), kw...) + yticks!(plt::PlotOrSubplot, + ticks::AVec{T}, labels::AVec{S}; kw...) where {T<:Real,S<:AbstractString} = plot!(plt; yticks = (ticks,labels), 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...) + annotate!(plt::PlotOrSubplot, anns::AVec{T}; kw...) where {T<:Tuple} = plot!(plt; annotation = anns, kw...) xflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; xflip = flip, kw...) yflip!(plt::PlotOrSubplot, flip::Bool = true; kw...) = plot!(plt; yflip = flip, kw...) xaxis!(plt::PlotOrSubplot, args...; kw...) = plot!(plt; xaxis = args, kw...) diff --git a/src/animation.jl b/src/animation.jl index 4afa01cf..b7a13684 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -1,5 +1,5 @@ "Represents an animation object" -immutable Animation +struct Animation dir::String frames::Vector{String} end @@ -14,7 +14,7 @@ end Add a plot (the current plot if not specified) to an existing animation """ -function frame{P<:AbstractPlot}(anim::Animation, plt::P=current()) +function frame(anim::Animation, plt::P=current()) where P<:AbstractPlot i = length(anim.frames) + 1 filename = @sprintf("%06d.png", i) png(plt, joinpath(anim.dir, filename)) @@ -25,7 +25,7 @@ giffn() = (isijulia() ? "tmp.gif" : tempname()*".gif") movfn() = (isijulia() ? "tmp.mov" : tempname()*".mov") mp4fn() = (isijulia() ? "tmp.mp4" : tempname()*".mp4") -type FrameIterator +mutable struct FrameIterator itr every::Int kw @@ -54,7 +54,7 @@ end # ----------------------------------------------- "Wraps the location of an animated gif so that it can be displayed" -immutable AnimatedGif +struct AnimatedGif filename::String end diff --git a/src/args.jl b/src/args.jl index f049f68f..81cf03f8 100644 --- a/src/args.jl +++ b/src/args.jl @@ -889,7 +889,7 @@ end # ----------------------------------------------------------------------------- "A special type that will break up incoming data into groups, and allow for easier creation of grouped plots" -type GroupBy +mutable struct GroupBy groupLabels::Vector # length == numGroups groupIds::Vector{Vector{Int}} # list of indices for each group end @@ -916,7 +916,7 @@ function extractGroupArgs(vs::Tuple, args...) end # expecting a mapping of "group label" to "group indices" -function extractGroupArgs{T, V<:AVec{Int}}(idxmap::Dict{T,V}, args...) +function extractGroupArgs(idxmap::Dict{T,V}, args...) where {T, V<:AVec{Int}} groupLabels = sortedkeys(idxmap) groupIds = Vector{Int}[collect(idxmap[k]) for k in groupLabels] GroupBy(groupLabels, groupIds) @@ -1007,7 +1007,7 @@ function convertLegendValue(val::Symbol) end convertLegendValue(val::Bool) = val ? :best : :none convertLegendValue(val::Void) = :none -convertLegendValue{S<:Real, T<:Real}(v::Tuple{S,T}) = v +convertLegendValue(v::Tuple{S,T}) where {S<:Real, T<:Real} = v convertLegendValue(v::AbstractArray) = map(convertLegendValue, v) # ----------------------------------------------------------------------------- diff --git a/src/axes.jl b/src/axes.jl index 25e45694..4288cde3 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -293,13 +293,13 @@ expand_extrema!(axis::Axis, ::Void) = axis[:extrema] expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] -function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX}) +function expand_extrema!(axis::Axis, v::Tuple{MIN,MAX}) where {MIN<:Number,MAX<:Number} ex = axis[:extrema] ex.emin = NaNMath.min(v[1], ex.emin) ex.emax = NaNMath.max(v[2], ex.emax) ex end -function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N}) +function expand_extrema!(axis::Axis, v::AVec{N}) where N<:Number ex = axis[:extrema] for vi in v expand_extrema!(ex, vi) diff --git a/src/backends.jl b/src/backends.jl index b445807c..1dd5d8ad 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -1,5 +1,5 @@ -immutable NoBackend <: AbstractBackend end +struct NoBackend <: AbstractBackend end const _backendType = Dict{Symbol, DataType}(:none => NoBackend) const _backendSymbol = Dict{DataType, Symbol}(NoBackend => :none) @@ -18,7 +18,7 @@ macro init_backend(s) sym = Symbol(str) T = Symbol(string(s) * "Backend") esc(quote - immutable $T <: AbstractBackend end + struct $T <: AbstractBackend end export $sym $sym(; kw...) = (default(; kw...); backend(Symbol($str))) backend_name(::$T) = Symbol($str) @@ -123,7 +123,7 @@ _update_plot_object(plt::Plot) = nothing # --------------------------------------------------------- -type CurrentBackend +mutable struct CurrentBackend sym::Symbol pkg::AbstractBackend end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index bbd5605a..716ce78a 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -69,9 +69,9 @@ function _initialize_backend(::GLVisualizeBackend; kw...) import GLVisualize: visualize import Plots.GL import UnicodeFun - Plots.slice_arg{C<:Colorant}(img::Matrix{C}, idx::Int) = img + Plots.slice_arg(img::Matrix{C}, idx::Int) where {C<:Colorant} = img is_marker_supported(::GLVisualizeBackend, shape::GLVisualize.AllPrimitives) = true - is_marker_supported{C<:Colorant}(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) = true + is_marker_supported(::GLVisualizeBackend, shape::Union{Vector{Matrix{C}}, Matrix{C}}) where {C<:Colorant} = true is_marker_supported(::GLVisualizeBackend, shape::Shape) = true const GL = Plots end @@ -214,13 +214,13 @@ function extract_limits(sp, d, kw_args) nothing end -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, vec::T) = vec -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, s::Number) = T(s) +to_vec(::Type{T}, vec::T) where {T <: StaticArrays.StaticVector} = vec +to_vec(::Type{T}, s::Number) where {T <: StaticArrays.StaticVector} = T(s) -to_vec{T <: StaticArrays.StaticVector{2}}(::Type{T}, vec::StaticArrays.StaticVector{3}) = T(vec[1], vec[2]) -to_vec{T <: StaticArrays.StaticVector{3}}(::Type{T}, vec::StaticArrays.StaticVector{2}) = T(vec[1], vec[2], 0) +to_vec(::Type{T}, vec::StaticArrays.StaticVector{3}) where {T <: StaticArrays.StaticVector{2}} = T(vec[1], vec[2]) +to_vec(::Type{T}, vec::StaticArrays.StaticVector{2}) where {T <: StaticArrays.StaticVector{3}} = T(vec[1], vec[2], 0) -to_vec{T <: StaticArrays.StaticVector}(::Type{T}, vecs::AbstractVector) = map(x-> to_vec(T, x), vecs) +to_vec(::Type{T}, vecs::AbstractVector) where {T <: StaticArrays.StaticVector} = map(x-> to_vec(T, x), vecs) function extract_marker(d, kw_args) dim = Plots.is3d(d) ? 3 : 2 @@ -275,7 +275,7 @@ end function extract_surface(d) map(_extract_surface, (d[:x], d[:y], d[:z])) end -function topoints{P}(::Type{P}, array) +function topoints(::Type{P}, array) where P [P(x) for x in zip(array...)] end function extract_points(d) @@ -283,7 +283,7 @@ function extract_points(d) array = (d[:x], d[:y], d[:z])[1:dim] topoints(Point{dim, Float32}, array) end -function make_gradient{C <: Colorant}(grad::Vector{C}) +function make_gradient(grad::Vector{C}) where C <: Colorant grad end function make_gradient(grad::ColorGradient) @@ -338,7 +338,7 @@ function extract_color(d, sym) end gl_color(c::PlotUtils.ColorGradient) = c.colors -gl_color{T<:Colorant}(c::Vector{T}) = c +gl_color(c::Vector{T}) where {T<:Colorant} = c gl_color(c::RGBA{Float32}) = c gl_color(c::Colorant) = RGBA{Float32}(c) @@ -1212,7 +1212,7 @@ function gl_image(img, kw_args) visualize(img, Style(:default), kw_args) end -function handle_segment{P}(lines, line_segments, points::Vector{P}, segment) +function handle_segment(lines, line_segments, points::Vector{P}, segment) where P (isempty(segment) || length(segment) < 2) && return if length(segment) == 2 append!(line_segments, view(points, segment)) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 96ca08f4..791055ed 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -482,7 +482,7 @@ function gr_legend_pos(s::Symbol,w,h) (xpos,ypos) end -function gr_legend_pos{S<:Real, T<:Real}(v::Tuple{S,T},w,h) +function gr_legend_pos(v::Tuple{S,T},w,h) where {S<:Real, T<:Real} xpos = v[1] * (viewport_plotarea[2] - viewport_plotarea[1]) + viewport_plotarea[1] ypos = v[2] * (viewport_plotarea[4] - viewport_plotarea[3]) + viewport_plotarea[3] (xpos,ypos) diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index a3a200ad..3adc912a 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -32,10 +32,10 @@ Read from .hdf5 file using: import FixedPointNumbers: N0f8 #In core Julia #Dispatch types: -immutable HDF5PlotNative; end #Indentifies a data element that can natively be handled by HDF5 -immutable HDF5CTuple; end #Identifies a "complex" tuple structure +struct HDF5PlotNative; end #Indentifies a data element that can natively be handled by HDF5 +struct HDF5CTuple; end #Identifies a "complex" tuple structure -type HDF5Plot_PlotRef +mutable struct HDF5Plot_PlotRef ref::Union{Plot, Void} end @@ -276,11 +276,11 @@ function _hdf5plot_overwritetype(grp, T::Type) #Write directly to group HDF5.a_delete(grp, _hdf5plot_datatypeid) HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end -function _hdf5plot_writetype{T<:Any}(grp, ::Type{Array{T}}) +function _hdf5plot_writetype(grp, ::Type{Array{T}}) where T<:Any tstr = HDF5PLOT_MAP_TELEM2STR[Array] #ANY HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end -function _hdf5plot_writetype{T<:BoundingBox}(grp, ::Type{T}) +function _hdf5plot_writetype(grp, ::Type{T}) where T<:BoundingBox tstr = HDF5PLOT_MAP_TELEM2STR[BoundingBox] HDF5.a_write(grp, _hdf5plot_datatypeid, tstr) end @@ -305,7 +305,7 @@ function _hdf5plot_gwrite(grp, k::String, v) #Default grp[k] = v _hdf5plot_writetype(grp, k, HDF5PlotNative) end -function _hdf5plot_gwrite{T<:Number}(grp, k::String, v::Array{T}) #Default for arrays +function _hdf5plot_gwrite(grp, k::String, v::Array{T}) where T<:Number #Default for arrays grp[k] = v _hdf5plot_writetype(grp, k, HDF5PlotNative) end @@ -355,7 +355,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Colorant) _hdf5plot_gwrite(grp, k, ARGB{N0f8}(v)) end #Custom vector (when not using simple numeric type): -function _hdf5plot_gwritearray{T}(grp, k::String, v::Array{T}) +function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T if "annotations" == k; return #Hack. Does not yet support annotations. end @@ -380,7 +380,7 @@ function _hdf5plot_gwrite(grp, k::String, v::Extrema) grp[k] = [v.emin, v.emax] _hdf5plot_writetype(grp, k, Extrema) end -function _hdf5plot_gwrite{T}(grp, k::String, v::Length{T}) +function _hdf5plot_gwrite(grp, k::String, v::Length{T}) where T grp[k] = v.value _hdf5plot_writetype(grp, k, [HDF5PLOT_MAP_TELEM2STR[Length], string(T)]) end diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index a8224634..65f019a0 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -131,7 +131,7 @@ end function _inspectdr_getscale(s::Symbol, yaxis::Bool) #TODO: Support :asinh, :sqrt - kwargs = yaxis? (:tgtmajor=>8, :tgtminor=>2): () #More grid lines on y-axis + kwargs = yaxis ? (:tgtmajor=>8, :tgtminor=>2) : () #More grid lines on y-axis if :log2 == s return InspectDR.AxisScale(:log2; kwargs...) elseif :log10 == s @@ -163,7 +163,7 @@ function _initialize_backend(::InspectDRBackend; kw...) 2*InspectDR.GLYPH_SQUARE.x, InspectDR.GLYPH_SQUARE.y ) - type InspecDRPlotRef + mutable struct InspecDRPlotRef mplot::Union{Void, InspectDR.Multiplot} gui::Union{Void, InspectDR.GtkPlot} end @@ -172,7 +172,7 @@ function _initialize_backend(::InspectDRBackend; kw...) _inspectdr_getmplot(r::InspecDRPlotRef) = r.mplot _inspectdr_getgui(::Any) = nothing - _inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed? nothing: gplot) + _inspectdr_getgui(gplot::InspectDR.GtkPlot) = (gplot.destroyed ? nothing : gplot) _inspectdr_getgui(r::InspecDRPlotRef) = _inspectdr_getgui(r.gui) end end @@ -235,7 +235,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) #Don't do anything without a "subplot" object: Will process later. if nothing == plot; return; end - _vectorize(v) = isa(v, Vector)? v: collect(v) #InspectDR only supports vectors + _vectorize(v) = isa(v, Vector) ? v : collect(v) #InspectDR only supports vectors x = _vectorize(series[:x]); y = _vectorize(series[:y]) #No support for polar grid... but can still perform polar transformation: @@ -278,7 +278,7 @@ For st in :shape: end end - i = (nmax >= 2? div(nmax, 2): nmax) #Must pick one set of colors for legend + i = (nmax >= 2 ? div(nmax, 2) : nmax) #Must pick one set of colors for legend if i > 1 #Add dummy waveform for legend entry: linewidth = series[:linewidth] linecolor = _inspectdr_mapcolor(_cycle(series[:linecolor], i)) @@ -296,7 +296,7 @@ For st in :shape: #NOTE: In Plots.jl, :scatter plots have 0-linewidths (I think). linewidth = series[:linewidth] #More efficient & allows some support for markerstrokewidth: - _style = (0==linewidth? :none: series[:linestyle]) + _style = (0==linewidth ? :none : series[:linestyle]) wfrm = InspectDR.add(plot, x, y, id=series[:label]) wfrm.line = InspectDR.line( style = _style, diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index c67511d2..f5ee90fa 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -122,7 +122,7 @@ const _plotly_legend_pos = KW( ) plotly_legend_pos(pos::Symbol) = get(_plotly_legend_pos, pos, [1.,1.]) -plotly_legend_pos{S<:Real, T<:Real}(v::Tuple{S,T}) = v +plotly_legend_pos(v::Tuple{S,T}) where {S<:Real, T<:Real} = v function plotly_font(font::Font, color = font.color) KW( @@ -441,7 +441,7 @@ end plotly_data(v) = collect(v) plotly_data(surf::Surface) = surf.surf -plotly_data{R<:Rational}(v::AbstractArray{R}) = float(v) +plotly_data(v::AbstractArray{R}) where {R<:Rational} = float(v) plotly_surface_data(series::Series, a::AbstractVector) = a plotly_surface_data(series::Series, a::AbstractMatrix) = transpose_z(series, a, false) diff --git a/src/components.jl b/src/components.jl index eba135c2..25784f1e 100644 --- a/src/components.jl +++ b/src/components.jl @@ -11,7 +11,7 @@ compute_angle(v::P2) = (angle = atan2(v[2], v[1]); angle < 0 ? 2π - angle : ang # ------------------------------------------------------------- -immutable Shape +struct Shape x::Vector{Float64} y::Vector{Float64} # function Shape(x::AVec, y::AVec) @@ -246,7 +246,7 @@ end # ----------------------------------------------------------------------- -type Font +mutable struct Font family::AbstractString pointsize::Int halign::Symbol @@ -336,7 +336,7 @@ function scalefontsizes() end "Wrap a string with font info" -immutable PlotText +struct PlotText str::AbstractString font::Font end @@ -359,7 +359,7 @@ Base.length(t::PlotText) = length(t.str) # ----------------------------------------------------------------------- -immutable Stroke +struct Stroke width color alpha @@ -401,7 +401,7 @@ function stroke(args...; alpha = nothing) end -immutable Brush +struct Brush size # fillrange, markersize, or any other sizey attribute color alpha @@ -434,7 +434,7 @@ end # ----------------------------------------------------------------------- -type SeriesAnnotations +mutable struct SeriesAnnotations strs::AbstractVector # the labels/names font::Font baseshape::Nullable @@ -513,7 +513,7 @@ function series_annotations_shapes!(series::Series, scaletype::Symbol = :pixels) return end -type EachAnn +mutable struct EachAnn anns x y @@ -538,12 +538,12 @@ annotations(sa::SeriesAnnotations) = sa # ----------------------------------------------------------------------- "type which represents z-values for colors and sizes (and anything else that might come up)" -immutable ZValues +struct ZValues values::Vector{Float64} zrange::Tuple{Float64,Float64} end -function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (ignorenan_minimum(values), ignorenan_maximum(values))) +function zvalues(values::AVec{T}, zrange::Tuple{T,T} = (ignorenan_minimum(values), ignorenan_maximum(values))) where T<:Real ZValues(collect(float(values)), map(Float64, zrange)) end @@ -552,7 +552,7 @@ end abstract type AbstractSurface end "represents a contour or surface mesh" -immutable Surface{M<:AMat} <: AbstractSurface +struct Surface{M<:AMat} <: AbstractSurface surf::M end @@ -564,7 +564,7 @@ for f in (:length, :size) @eval Base.$f(surf::Surface, args...) = $f(surf.surf, args...) end Base.copy(surf::Surface) = Surface(copy(surf.surf)) -Base.eltype{T}(surf::Surface{T}) = eltype(T) +Base.eltype(surf::Surface{T}) where {T} = eltype(T) function expand_extrema!(a::Axis, surf::Surface) ex = a[:extrema] @@ -575,7 +575,7 @@ function expand_extrema!(a::Axis, surf::Surface) end "For the case of representing a surface as a function of x/y... can possibly avoid allocations." -immutable SurfaceFunction <: AbstractSurface +struct SurfaceFunction <: AbstractSurface f::Function end @@ -585,19 +585,19 @@ end # # I don't want to clash with ValidatedNumerics, but this would be nice: # ..(a::T, b::T) = (a,b) -immutable Volume{T} +struct Volume{T} v::Array{T,3} x_extents::Tuple{T,T} y_extents::Tuple{T,T} z_extents::Tuple{T,T} end -default_extents{T}(::Type{T}) = (zero(T), one(T)) +default_extents(::Type{T}) where {T} = (zero(T), one(T)) -function Volume{T}(v::Array{T,3}, - x_extents = default_extents(T), - y_extents = default_extents(T), - z_extents = default_extents(T)) +function Volume(v::Array{T,3}, + x_extents = default_extents(T), + y_extents = default_extents(T), + z_extents = default_extents(T)) where T Volume(v, x_extents, y_extents, z_extents) end @@ -605,13 +605,13 @@ Base.Array(vol::Volume) = vol.v for f in (:length, :size) @eval Base.$f(vol::Volume, args...) = $f(vol.v, args...) end -Base.copy{T}(vol::Volume{T}) = Volume{T}(copy(vol.v), vol.x_extents, vol.y_extents, vol.z_extents) -Base.eltype{T}(vol::Volume{T}) = T +Base.copy(vol::Volume{T}) where {T} = Volume{T}(copy(vol.v), vol.x_extents, vol.y_extents, vol.z_extents) +Base.eltype(vol::Volume{T}) where {T} = T # ----------------------------------------------------------------------- # style is :open or :closed (for now) -immutable Arrow +struct Arrow style::Symbol side::Symbol # :head (default), :tail, or :both headlength::Float64 @@ -673,14 +673,14 @@ end # ----------------------------------------------------------------------- "Represents data values with formatting that should apply to the tick labels." -immutable Formatted{T} +struct Formatted{T} data::T formatter::Function end # ----------------------------------------------------------------------- "create a BezierCurve for plotting" -type BezierCurve{T <: FixedSizeArrays.Vec} +mutable struct BezierCurve{T <: FixedSizeArrays.Vec} control_points::Vector{T} end diff --git a/src/deprecated/backends/gadfly.jl b/src/deprecated/backends/gadfly.jl index bb501db2..53453b9e 100644 --- a/src/deprecated/backends/gadfly.jl +++ b/src/deprecated/backends/gadfly.jl @@ -558,7 +558,7 @@ function createGadflyAnnotationObject(x, y, txt::PlotText) )) end -function _add_annotations{X,Y,V}(plt::Plot{GadflyBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{GadflyBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns push!(plt.o.guides, createGadflyAnnotationObject(ann...)) end @@ -614,7 +614,7 @@ function getxy(plt::Plot{GadflyBackend}, i::Integer) mapping[:x], mapping[:y] end -function setxy!{X,Y}(plt::Plot{GadflyBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{GadflyBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} for mapping in getGadflyMappings(plt, i) mapping[:x], mapping[:y] = xy end @@ -677,7 +677,7 @@ setGadflyDisplaySize(plt::Plot) = setGadflyDisplaySize(plt.attr[:size]...) # ------------------------------------------------------------------------- -function doshow{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, func, plt::AbstractPlot{P}) +function doshow(io::IO, func, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} gplt = getGadflyContext(plt) setGadflyDisplaySize(plt) Gadfly.draw(func(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) @@ -692,7 +692,7 @@ getGadflyWriteFunc(::MIME"application/x-tex") = Gadfly.PGF getGadflyWriteFunc(m::MIME) = error("Unsupported in Gadfly/Immerse: ", m) for mime in (MIME"image/png", MIME"image/svg+xml", MIME"application/pdf", MIME"application/postscript", MIME"application/x-tex") - @eval function Base.show{P<:Union{GadflyBackend,ImmerseBackend}}(io::IO, ::$mime, plt::AbstractPlot{P}) + @eval function Base.show(io::IO, ::$mime, plt::AbstractPlot{P}) where P<:Union{GadflyBackend,ImmerseBackend} func = getGadflyWriteFunc($mime()) doshow(io, func, plt) end diff --git a/src/deprecated/backends/gadfly_shapes.jl b/src/deprecated/backends/gadfly_shapes.jl index 9c70c90c..1a818993 100644 --- a/src/deprecated/backends/gadfly_shapes.jl +++ b/src/deprecated/backends/gadfly_shapes.jl @@ -2,7 +2,7 @@ # Geometry which displays arbitrary shapes at given (x, y) positions. # note: vertices is a list of shapes -immutable ShapeGeometry <: Gadfly.GeometryElement +struct ShapeGeometry <: Gadfly.GeometryElement vertices::AbstractVector #{Tuple{Float64,Float64}} tag::Symbol diff --git a/src/deprecated/backends/immerse.jl b/src/deprecated/backends/immerse.jl index b8679cf3..58950480 100644 --- a/src/deprecated/backends/immerse.jl +++ b/src/deprecated/backends/immerse.jl @@ -61,7 +61,7 @@ end # ---------------------------------------------------------------- -function _add_annotations{X,Y,V}(plt::Plot{ImmerseBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{ImmerseBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns push!(getGadflyContext(plt).guides, createGadflyAnnotationObject(ann...)) end @@ -76,7 +76,7 @@ function getxy(plt::Plot{ImmerseBackend}, i::Integer) mapping[:x], mapping[:y] end -function setxy!{X,Y}(plt::Plot{ImmerseBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{ImmerseBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} for mapping in getGadflyMappings(plt, i) mapping[:x], mapping[:y] = xy end diff --git a/src/deprecated/backends/qwt.jl b/src/deprecated/backends/qwt.jl index 2173c599..6bffd322 100644 --- a/src/deprecated/backends/qwt.jl +++ b/src/deprecated/backends/qwt.jl @@ -218,7 +218,7 @@ function createQwtAnnotation(plt::Plot, x, y, val::AbstractString) marker[:attach](plt.o.widget) end -function _add_annotations{X,Y,V}(plt::Plot{QwtBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{QwtBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns createQwtAnnotation(plt, ann...) end @@ -233,7 +233,7 @@ function getxy(plt::Plot{QwtBackend}, i::Int) series.x, series.y end -function setxy!{X,Y}(plt::Plot{QwtBackend}, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot{QwtBackend}, xy::Tuple{X,Y}, i::Integer) where {X,Y} series = plt.o.lines[i] series.x, series.y = xy plt diff --git a/src/deprecated/backends/winston.jl b/src/deprecated/backends/winston.jl index 8e7b97c7..22694be8 100644 --- a/src/deprecated/backends/winston.jl +++ b/src/deprecated/backends/winston.jl @@ -217,7 +217,7 @@ function createWinstonAnnotationObject(plt::Plot{WinstonBackend}, x, y, val::Abs Winston.text(x, y, val) end -function _add_annotations{X,Y,V}(plt::Plot{WinstonBackend}, anns::AVec{Tuple{X,Y,V}}) +function _add_annotations(plt::Plot{WinstonBackend}, anns::AVec{Tuple{X,Y,V}}) where {X,Y,V} for ann in anns createWinstonAnnotationObject(plt, ann...) end diff --git a/src/deprecated/colors.jl b/src/deprecated/colors.jl index f73d5db6..8247529a 100644 --- a/src/deprecated/colors.jl +++ b/src/deprecated/colors.jl @@ -34,9 +34,9 @@ getColorVector(scheme::ColorScheme) = [getColor(scheme)] colorscheme(scheme::ColorScheme) = scheme colorscheme(s::AbstractString; kw...) = colorscheme(Symbol(s); kw...) colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...) -colorscheme{T<:Real}(s::Symbol, vals::AVec{T}; kw...) = ColorGradient(s, vals; kw...) +colorscheme(s::Symbol, vals::AVec{T}; kw...) where {T<:Real} = ColorGradient(s, vals; kw...) colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...) -colorscheme{T<:Colorant}(cs::AVec{T}; kw...) = ColorGradient(cs; kw...) +colorscheme(cs::AVec{T}; kw...) where {T<:Colorant} = ColorGradient(cs; kw...) colorscheme(f::Function; kw...) = ColorFunction(f; kw...) colorscheme(v::AVec; kw...) = ColorVector(v; kw...) colorscheme(m::AMat; kw...) = size(m,1) == 1 ? map(c->colorscheme(c; kw...), m) : [colorscheme(m[:,i]; kw...) for i in 1:size(m,2)]' @@ -98,7 +98,7 @@ const _gradients = KW( :lighttest => map(c -> lighten(c, 0.3), _testColors), ) -function register_gradient_colors{C<:Colorant}(name::Symbol, colors::AVec{C}) +function register_gradient_colors(name::Symbol, colors::AVec{C}) where C<:Colorant _gradients[name] = colors end @@ -109,11 +109,11 @@ default_gradient() = ColorGradient(:inferno) # -------------------------------------------------------------- "Continuous gradient between values. Wraps a list of bounding colors and the values they represent." -immutable ColorGradient <: ColorScheme +struct ColorGradient <: ColorScheme colors::Vector values::Vector - function ColorGradient{S<:Real}(cs::AVec, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing) + function ColorGradient(cs::AVec, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing) where S<:Real if length(cs) == length(vals) return new(convertColor(cs,alpha), collect(vals)) end @@ -138,7 +138,7 @@ Base.getindex(cs::ColorGradient, z::Number) = getColorZ(cs, z) # create a gradient from a symbol (blues, reds, etc) and vector of boundary values -function ColorGradient{T<:Real}(s::Symbol, vals::AVec{T} = 0:0; kw...) +function ColorGradient(s::Symbol, vals::AVec{T} = 0:0; kw...) where T<:Real haskey(_gradients, s) || error("Invalid gradient symbol. Choose from: ", sort(collect(keys(_gradients)))) cs = _gradients[s] if vals == 0:0 @@ -208,7 +208,7 @@ end # -------------------------------------------------------------- "Wraps a function, taking an index and returning a Colorant" -immutable ColorFunction <: ColorScheme +struct ColorFunction <: ColorScheme f::Function end @@ -217,7 +217,7 @@ getColor(scheme::ColorFunction, idx::Int) = scheme.f(idx) # -------------------------------------------------------------- "Wraps a function, taking an z-value and returning a Colorant" -immutable ColorZFunction <: ColorScheme +struct ColorZFunction <: ColorScheme f::Function end @@ -226,7 +226,7 @@ getColorZ(scheme::ColorZFunction, z::Real) = scheme.f(z) # -------------------------------------------------------------- "Wraps a vector of colors... may be vector of Symbol/String/Colorant" -immutable ColorVector <: ColorScheme +struct ColorVector <: ColorScheme v::Vector{Colorant} ColorVector(v::AVec; alpha = nothing) = new(convertColor(v,alpha)) end @@ -238,7 +238,7 @@ getColorVector(scheme::ColorVector) = scheme.v # -------------------------------------------------------------- "Wraps a single color" -immutable ColorWrapper <: ColorScheme +struct ColorWrapper <: ColorScheme c::RGBA ColorWrapper(c::Colorant; alpha = nothing) = new(convertColor(c, alpha)) end @@ -347,8 +347,8 @@ function get_color_palette(palette, bgcolor::Union{Colorant,ColorWrapper}, numco RGBA[getColorZ(grad, z) for z in zrng] end -function get_color_palette{C<:Colorant}(palette::Vector{C}, - bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) +function get_color_palette(palette::Vector{C}, +bgcolor::Union{Colorant,ColorWrapper}, numcolors::Integer) where C<:Colorant palette end diff --git a/src/deprecated/series_args.jl b/src/deprecated/series_args.jl index 2d7536f4..b5b02594 100644 --- a/src/deprecated/series_args.jl +++ b/src/deprecated/series_args.jl @@ -5,21 +5,21 @@ # This should cut down on boilerplate code and allow more focused dispatch on type # note: returns meta information... mainly for use with automatic labeling from DataFrames for now -const FuncOrFuncs = @compat(Union{Function, AVec{Function}}) +const FuncOrFuncs = Union{Function, AVec{Function}} all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) # missing -convertToAnyVector(v::@compat(Void), d::KW) = Any[nothing], nothing +convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing # fixed number of blank series convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing # numeric vector -convertToAnyVector{T<:Number}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing # string vector -convertToAnyVector{T<:@compat(AbstractString)}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing function convertToAnyVector(v::AMat, d::KW) if all3D(d) @@ -39,7 +39,7 @@ convertToAnyVector(s::Surface, d::KW) = Any[s], nothing # convertToAnyVector(v::AVec{OHLC}, d::KW) = Any[v], nothing # dates -convertToAnyVector{D<:Union{Date,DateTime}}(dts::AVec{D}, d::KW) = Any[dts], nothing +convertToAnyVector(dts::AVec{D}, d::KW) where {D<:Union{Date,DateTime}} = Any[dts], nothing # list of things (maybe other vectors, functions, or something else) function convertToAnyVector(v::AVec, d::KW) diff --git a/src/examples.jl b/src/examples.jl index ed62e00e..3f8acaa3 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -1,7 +1,7 @@ """ Holds all data needed for a documentation example... header, description, and plotting expression (Expr) """ -type PlotExample +mutable struct PlotExample header::AbstractString desc::AbstractString exprs::Vector{Expr} diff --git a/src/layouts.jl b/src/layouts.jl index 9bd4d3b2..63924374 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -13,7 +13,7 @@ Base.zero(::Type{typeof(mm)}) = 0mm Base.one(::Type{typeof(mm)}) = 1mm Base.typemin(::typeof(mm)) = -Inf*mm Base.typemax(::typeof(mm)) = Inf*mm -Base.convert{F<:AbstractFloat}(::Type{F}, l::AbsoluteLength) = convert(F, l.value) +Base.convert(::Type{F}, l::AbsoluteLength) where {F<:AbstractFloat} = convert(F, l.value) # TODO: these are unintuitive and may cause tricky bugs # Base.:+(m1::AbsoluteLength, m2::Length{:pct}) = AbsoluteLength(m1.value * (1 + m2.value)) @@ -95,7 +95,7 @@ end # ----------------------------------------------------------- # points combined by x/y, pct, and length -type MixedMeasures +mutable struct MixedMeasures xy::Float64 pct::Float64 len::AbsoluteLength @@ -216,7 +216,7 @@ bottompad(layout::AbstractLayout) = 0mm # RootLayout # this is the parent of the top-level layout -immutable RootLayout <: AbstractLayout end +struct RootLayout <: AbstractLayout end Base.parent(::RootLayout) = nothing parent_bbox(::RootLayout) = defaultbox @@ -226,7 +226,7 @@ bbox(::RootLayout) = defaultbox # EmptyLayout # contains blank space -type EmptyLayout <: AbstractLayout +mutable struct EmptyLayout <: AbstractLayout parent::AbstractLayout bbox::BoundingBox attr::KW # store label, width, and height for initialization @@ -244,7 +244,7 @@ _update_min_padding!(layout::EmptyLayout) = nothing # GridLayout # nested, gridded layout with optional size percentages -type GridLayout <: AbstractLayout +mutable struct GridLayout <: AbstractLayout parent::AbstractLayout minpad::Tuple # leftpad, toppad, rightpad, bottompad bbox::BoundingBox @@ -481,12 +481,12 @@ function layout_args(n::Integer) GridLayout(nr, nc), n end -function layout_args{I<:Integer}(sztup::NTuple{2,I}) +function layout_args(sztup::NTuple{2,I}) where I<:Integer nr, nc = sztup GridLayout(nr, nc), nr*nc end -function layout_args{I<:Integer}(sztup::NTuple{3,I}) +function layout_args(sztup::NTuple{3,I}) where I<:Integer n, nr, nc = sztup nr, nc = compute_gridsize(n, nr, nc) GridLayout(nr, nc), n diff --git a/src/output.jl b/src/output.jl index f26b6720..37849d8b 100644 --- a/src/output.jl +++ b/src/output.jl @@ -193,7 +193,7 @@ function Base.show(io::IO, ::MIME"text/html", plt::Plot) end end -function _show{B}(io::IO, m, plt::Plot{B}) +function _show(io::IO, m, plt::Plot{B}) where B # Base.show_backtrace(STDOUT, backtrace()) warn("_show is not defined for this backend. m=", string(m)) end @@ -203,7 +203,7 @@ end # for writing to io streams... first prepare, then callback for mime in keys(_mimeformats) - @eval function Base.show{B}(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B}) + @eval function Base.show(io::IO, m::MIME{Symbol($mime)}, plt::Plot{B}) where B prepare_output(plt) _show(io, m, plt) end @@ -293,7 +293,7 @@ end Media.media(Plot, Media.Plot) - _show{B}(io::IO, m::MIME"text/plain", plt::Plot{B}) = print(io, "Plot{$B}()") + _show(io::IO, m::MIME"text/plain", plt::Plot{B}) where {B} = print(io, "Plot{$B}()") function Juno.render(e::Juno.Editor, plt::Plot) Juno.render(e, nothing) diff --git a/src/pipeline.jl b/src/pipeline.jl index a0f17ba4..e8607337 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -301,7 +301,7 @@ end # getting ready to add the series... last update to subplot from anything # that might have been added during series recipes -function _prepare_subplot{T}(plt::Plot{T}, d::KW) +function _prepare_subplot(plt::Plot{T}, d::KW) where T st::Symbol = d[:seriestype] sp::Subplot{T} = d[:subplot] sp_idx = get_subplot_index(plt, sp) diff --git a/src/plot.jl b/src/plot.jl index 8968df8c..38034bec 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -1,5 +1,5 @@ -type CurrentPlot +mutable struct CurrentPlot nullableplot::Nullable{AbstractPlot} end const CURRENT_PLOT = CurrentPlot(Nullable{AbstractPlot}()) diff --git a/src/recipes.jl b/src/recipes.jl index 5501351a..6e49fb03 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -47,7 +47,7 @@ end num_series(x::AMat) = size(x,2) num_series(x) = 1 -RecipesBase.apply_recipe{T}(d::KW, ::Type{T}, plt::AbstractPlot) = throw(MethodError("Unmatched plot recipe: $T")) +RecipesBase.apply_recipe(d::KW, ::Type{T}, plt::AbstractPlot) where {T} = throw(MethodError("Unmatched plot recipe: $T")) # --------------------------------------------------------------------------- @@ -343,9 +343,9 @@ _bin_centers(v::AVec) = (v[1:end-1] + v[2:end]) / 2 _is_positive(x) = (x > 0) && !(x ≈ 0) -_positive_else_nan{T}(::Type{T}, x::Real) = _is_positive(x) ? T(x) : T(NaN) +_positive_else_nan(::Type{T}, x::Real) where {T} = _is_positive(x) ? T(x) : T(NaN) -function _scale_adjusted_values{T<:AbstractFloat}(::Type{T}, V::AbstractVector, scale::Symbol) +function _scale_adjusted_values(::Type{T}, V::AbstractVector, scale::Symbol) where T<:AbstractFloat if scale in _logScales [_positive_else_nan(T, x) for x in V] else @@ -354,7 +354,7 @@ function _scale_adjusted_values{T<:AbstractFloat}(::Type{T}, V::AbstractVector, end -function _binbarlike_baseline{T<:Real}(min_value::T, scale::Symbol) +function _binbarlike_baseline(min_value::T, scale::Symbol) where T<:Real if (scale in _logScales) !isnan(min_value) ? min_value / T(_logScaleBases[scale]^log10(2)) : T(1E-3) else @@ -363,7 +363,7 @@ function _binbarlike_baseline{T<:Real}(min_value::T, scale::Symbol) end -function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) +function _preprocess_binbarlike_weights(::Type{T}, w, wscale::Symbol) where T<:AbstractFloat w_adj = _scale_adjusted_values(T, w, wscale) w_min = ignorenan_minimum(w_adj) w_max = ignorenan_maximum(w_adj) @@ -499,7 +499,7 @@ Plots.@deps stepbins path wand_edges(x...) = (warn("Load the StatPlots package in order to use :wand bins. Defaulting to :auto", once = true); :auto) -function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) +function _auto_binning_nbins(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) where N _cl(x) = ceil(Int, NaNMath.max(x, one(x))) _iqr(v) = (q = quantile(v, 0.75) - quantile(v, 0.25); q > 0 ? q : oftype(q, 1)) _span(v) = ignorenan_maximum(v) - ignorenan_minimum(v) @@ -533,20 +533,20 @@ function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode end end -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Integer) = StatsBase.histrange(vs[dim], binning, :left) -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) = _hist_edge(vs, dim, _auto_binning_nbins(vs, dim, mode = binning)) -_hist_edge{N}(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) = binning +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Integer) where {N} = StatsBase.histrange(vs[dim], binning, :left) +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::Symbol) where {N} = _hist_edge(vs, dim, _auto_binning_nbins(vs, dim, mode = binning)) +_hist_edge(vs::NTuple{N,AbstractVector}, dim::Integer, binning::AbstractVector) where {N} = binning -_hist_edges{N}(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) = +_hist_edges(vs::NTuple{N,AbstractVector}, binning::NTuple{N}) where {N} = map(dim -> _hist_edge(vs, dim, binning[dim]), (1:N...)) -_hist_edges{N}(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) = +_hist_edges(vs::NTuple{N,AbstractVector}, binning::Union{Integer, Symbol, AbstractVector}) where {N} = map(dim -> _hist_edge(vs, dim, binning), (1:N...)) _hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Bool) = mode ? :pdf : :none -function _make_hist{N}(vs::NTuple{N,AbstractVector}, binning; normed = false, weights = nothing) +function _make_hist(vs::NTuple{N,AbstractVector}, binning; normed = false, weights = nothing) where N edges = _hist_edges(vs, binning) h = float( weights == nothing ? StatsBase.fit(StatsBase.Histogram, vs, edges, closed = :left) : @@ -590,7 +590,7 @@ end @deps scatterhist scatterbins -@recipe function f{T, E}(h::StatsBase.Histogram{T, 1, E}) +@recipe function f(h::StatsBase.Histogram{T, 1, E}) where {T, E} seriestype --> :barbins st_map = Dict( @@ -611,7 +611,7 @@ end end -@recipe function f{H <: StatsBase.Histogram}(hv::AbstractVector{H}) +@recipe function f(hv::AbstractVector{H}) where H <: StatsBase.Histogram for h in hv @series begin h @@ -658,7 +658,7 @@ end @deps histogram2d bins2d -@recipe function f{T, E}(h::StatsBase.Histogram{T, 2, E}) +@recipe function f(h::StatsBase.Histogram{T, 2, E}) where {T, E} seriestype --> :bins2d (h.edges[1], h.edges[2], Surface(h.weights)) end @@ -855,7 +855,7 @@ end # TODO: move OHLC to PlotRecipes finance.jl "Represent Open High Low Close data (used in finance)" -type OHLC{T<:Real} +mutable struct OHLC{T<:Real} open::T high::T low::T @@ -894,10 +894,10 @@ end # to squash ambiguity warnings... @recipe f(x::AVec{Function}, v::AVec{OHLC}) = error() -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(x::AVec{Function}, v::AVec{Tuple{R1,R2,R3,R4}}) = error() +@recipe f(x::AVec{Function}, v::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = error() # this must be OHLC? -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(x::AVec, ohlc::AVec{Tuple{R1,R2,R3,R4}}) = x, OHLC[OHLC(t...) for t in ohlc] +@recipe f(x::AVec, ohlc::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = x, OHLC[OHLC(t...) for t in ohlc] @recipe function f(x::AVec, v::AVec{OHLC}) seriestype := :path @@ -987,7 +987,7 @@ datetimeformatter(dt) = string(DateTime(Dates.UTM(dt))) # ------------------------------------------------- # Complex Numbers -@recipe function f{T<:Number}(A::Array{Complex{T}}) +@recipe function f(A::Array{Complex{T}}) where T<:Number xguide --> "Re(x)" yguide --> "Im(x)" real.(A), imag.(A) @@ -996,7 +996,7 @@ end # Splits a complex matrix to its real and complex parts # Reals defaults solid, imaginary defaults dashed # Label defaults are changed to match the real-imaginary reference / indexing -@recipe function f{T<:Real,T2}(x::AbstractArray{T},y::Array{Complex{T2}}) +@recipe function f(x::AbstractArray{T},y::Array{Complex{T2}}) where {T<:Real,T2} ylabel --> "Re(y)" zlabel --> "Im(y)" x,real.(y),imag.(y) diff --git a/src/series.jl b/src/series.jl index c0d7d4c2..1f00bb6e 100644 --- a/src/series.jl +++ b/src/series.jl @@ -20,10 +20,10 @@ convertToAnyVector(v::Void, d::KW) = Any[nothing], nothing convertToAnyVector(n::Integer, d::KW) = Any[zeros(0) for i in 1:n], nothing # numeric vector -convertToAnyVector{T<:Number}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:Number} = Any[v], nothing # string vector -convertToAnyVector{T<:AbstractString}(v::AVec{T}, d::KW) = Any[v], nothing +convertToAnyVector(v::AVec{T}, d::KW) where {T<:AbstractString} = Any[v], nothing function convertToAnyVector(v::AMat, d::KW) if all3D(d) @@ -99,8 +99,8 @@ nobigs(v) = v end # not allowed -compute_xyz{F<:Function}(x::Void, y::FuncOrFuncs{F}, z) = error("If you want to plot the function `$y`, you need to define the x values!") -compute_xyz{F<:Function}(x::Void, y::Void, z::FuncOrFuncs{F}) = error("If you want to plot the function `$z`, you need to define x and y values!") +compute_xyz(x::Void, y::FuncOrFuncs{F}, z) where {F<:Function} = error("If you want to plot the function `$y`, you need to define the x values!") +compute_xyz(x::Void, y::Void, z::FuncOrFuncs{F}) where {F<:Function} = error("If you want to plot the function `$z`, you need to define x and y values!") compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") # -------------------------------------------------------------------- @@ -109,7 +109,7 @@ compute_xyz(x::Void, y::Void, z::Void) = error("x/y/z are all nothing!") # we are going to build recipes to do the processing and splitting of the args # ensure we dispatch to the slicer -immutable SliceIt end +struct SliceIt end # the catch-all recipes @recipe function f(::Type{SliceIt}, x, y, z) @@ -163,10 +163,10 @@ immutable SliceIt end end # this is the default "type recipe"... just pass the object through -@recipe f{T<:Any}(::Type{T}, v::T) = v +@recipe f(::Type{T}, v::T) where {T<:Any} = v # this should catch unhandled "series recipes" and error with a nice message -@recipe f{V<:Val}(::Type{V}, x, y, z) = error("The backend must not support the series type $V, and there isn't a series recipe defined.") +@recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.") _apply_type_recipe(d, v) = RecipesBase.apply_recipe(d, typeof(v), v)[1].args[1] @@ -201,7 +201,7 @@ end # end # don't do anything for ints or floats -_apply_type_recipe{T<:Union{Integer,AbstractFloat}}(d, v::AbstractArray{T}) = v +_apply_type_recipe(d, v::AbstractArray{T}) where {T<:Union{Integer,AbstractFloat}} = v # handle "type recipes" by converting inputs, and then either re-calling or slicing @recipe function f(x, y, z) @@ -274,7 +274,7 @@ end @recipe f(n::Integer) = is3d(get(plotattributes,:seriestype,:path)) ? (SliceIt, n, n, n) : (SliceIt, n, n, nothing) # return a surface if this is a 3d plot, otherwise let it be sliced up -@recipe function f{T<:Union{Integer,AbstractFloat}}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Union{Integer,AbstractFloat} if all3D(plotattributes) n,m = size(mat) wrap_surfaces(plotattributes) @@ -285,7 +285,7 @@ end end # if a matrix is wrapped by Formatted, do similar logic, but wrap data with Surface -@recipe function f{T<:AbstractMatrix}(fmt::Formatted{T}) +@recipe function f(fmt::Formatted{T}) where T<:AbstractMatrix if all3D(plotattributes) mat = fmt.data n,m = size(mat) @@ -297,7 +297,7 @@ end end # assume this is a Volume, so construct one -@recipe function f{T<:Number}(vol::AbstractArray{T,3}, args...) +@recipe function f(vol::AbstractArray{T,3}, args...) where T<:Number seriestype := :volume SliceIt, nothing, Volume(vol, args...), nothing end @@ -305,7 +305,7 @@ end # # images - grays -@recipe function f{T<:Gray}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Gray if is_seriestype_supported(:image) seriestype := :image n, m = size(mat) @@ -320,7 +320,7 @@ end # # images - colors -@recipe function f{T<:Colorant}(mat::AMat{T}) +@recipe function f(mat::AMat{T}) where T<:Colorant n, m = size(mat) if is_seriestype_supported(:image) @@ -358,7 +358,7 @@ end # function without range... use the current range of the x-axis -@recipe function f{F<:Function}(f::FuncOrFuncs{F}) +@recipe function f(f::FuncOrFuncs{F}) where F<:Function plt = plotattributes[:plot_object] xmin, xmax = try axis_limits(plt[1][:xaxis]) @@ -397,7 +397,7 @@ end # # if functions come first, just swap the order (not to be confused with parametric functions... # # as there would be more than one function passed in) -@recipe function f{F<:Function}(f::FuncOrFuncs{F}, x) +@recipe function f(f::FuncOrFuncs{F}, x) where F<:Function F2 = typeof(x) @assert !(F2 <: Function || (F2 <: AbstractArray && F2.parameters[1] <: Function)) # otherwise we'd hit infinite recursion here x, f @@ -465,19 +465,19 @@ end xs = adapted_grid(f, (xmin, xmax)) xs, f end -@recipe function f{F<:Function}(fs::AbstractArray{F}, xmin::Number, xmax::Number) +@recipe function f(fs::AbstractArray{F}, xmin::Number, xmax::Number) where F<:Function xs = Any[adapted_grid(f, (xmin, xmax)) for f in fs] xs, fs end -@recipe f{F<:Function,G<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u) -@recipe f{F<:Function,G<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) = fx, fy, linspace(umin, umax, n) +@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) where {F<:Function,G<:Function} = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u) +@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) where {F<:Function,G<:Function} = fx, fy, linspace(umin, umax, n) # # # special handling... 3D parametric function(s) -@recipe function f{F<:Function,G<:Function,H<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) +@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) where {F<:Function,G<:Function,H<:Function} mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u) end -@recipe function f{F<:Function,G<:Function,H<:Function}(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) +@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, umin::Number, umax::Number, numPoints = 200) where {F<:Function,G<:Function,H<:Function} fx, fy, fz, linspace(umin, umax, numPoints) end @@ -492,28 +492,28 @@ end # # # (x,y) tuples -@recipe f{R1<:Number,R2<:Number}(xy::AVec{Tuple{R1,R2}}) = unzip(xy) -@recipe f{R1<:Number,R2<:Number}(xy::Tuple{R1,R2}) = [xy[1]], [xy[2]] +@recipe f(xy::AVec{Tuple{R1,R2}}) where {R1<:Number,R2<:Number} = unzip(xy) +@recipe f(xy::Tuple{R1,R2}) where {R1<:Number,R2<:Number} = [xy[1]], [xy[2]] # # # (x,y,z) tuples -@recipe f{R1<:Number,R2<:Number,R3<:Number}(xyz::AVec{Tuple{R1,R2,R3}}) = unzip(xyz) -@recipe f{R1<:Number,R2<:Number,R3<:Number}(xyz::Tuple{R1,R2,R3}) = [xyz[1]], [xyz[2]], [xyz[3]] +@recipe f(xyz::AVec{Tuple{R1,R2,R3}}) where {R1<:Number,R2<:Number,R3<:Number} = unzip(xyz) +@recipe f(xyz::Tuple{R1,R2,R3}) where {R1<:Number,R2<:Number,R3<:Number} = [xyz[1]], [xyz[2]], [xyz[3]] # these might be points+velocity, or OHLC or something else -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::AVec{Tuple{R1,R2,R3,R4}}) = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv) -@recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::Tuple{R1,R2,R3,R4}) = [xyuv[1]], [xyuv[2]], [xyuv[3]], [xyuv[4]] +@recipe f(xyuv::AVec{Tuple{R1,R2,R3,R4}}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv) +@recipe f(xyuv::Tuple{R1,R2,R3,R4}) where {R1<:Number,R2<:Number,R3<:Number,R4<:Number} = [xyuv[1]], [xyuv[2]], [xyuv[3]], [xyuv[4]] # # # 2D FixedSizeArrays -@recipe f{T<:Number}(xy::AVec{FixedSizeArrays.Vec{2,T}}) = unzip(xy) -@recipe f{T<:Number}(xy::FixedSizeArrays.Vec{2,T}) = [xy[1]], [xy[2]] +@recipe f(xy::AVec{FixedSizeArrays.Vec{2,T}}) where {T<:Number} = unzip(xy) +@recipe f(xy::FixedSizeArrays.Vec{2,T}) where {T<:Number} = [xy[1]], [xy[2]] # # # 3D FixedSizeArrays -@recipe f{T<:Number}(xyz::AVec{FixedSizeArrays.Vec{3,T}}) = unzip(xyz) -@recipe f{T<:Number}(xyz::FixedSizeArrays.Vec{3,T}) = [xyz[1]], [xyz[2]], [xyz[3]] +@recipe f(xyz::AVec{FixedSizeArrays.Vec{3,T}}) where {T<:Number} = unzip(xyz) +@recipe f(xyz::FixedSizeArrays.Vec{3,T}) where {T<:Number} = [xyz[1]], [xyz[2]], [xyz[3]] # # # -------------------------------------------------------------------- diff --git a/src/subplots.jl b/src/subplots.jl index 5629125f..a47bc8ee 100644 --- a/src/subplots.jl +++ b/src/subplots.jl @@ -1,6 +1,6 @@ -function Subplot{T<:AbstractBackend}(::T; parent = RootLayout()) +function Subplot(::T; parent = RootLayout()) where T<:AbstractBackend Subplot{T}( parent, Series[], diff --git a/src/types.jl b/src/types.jl index 3e07587b..bd53715b 100644 --- a/src/types.jl +++ b/src/types.jl @@ -6,20 +6,20 @@ const AVec = AbstractVector const AMat = AbstractMatrix const KW = Dict{Symbol,Any} -immutable PlotsDisplay <: Display end +struct PlotsDisplay <: Display end # ----------------------------------------------------------- -immutable InputWrapper{T} +struct InputWrapper{T} obj::T end -wrap{T}(obj::T) = InputWrapper{T}(obj) +wrap(obj::T) where {T} = InputWrapper{T}(obj) Base.isempty(wrapper::InputWrapper) = false # ----------------------------------------------------------- -type Series +mutable struct Series d::KW end @@ -29,7 +29,7 @@ attr!(series::Series, v, k::Symbol) = (series.d[k] = v) # ----------------------------------------------------------- # a single subplot -type Subplot{T<:AbstractBackend} <: AbstractLayout +mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout parent::AbstractLayout series_list::Vector{Series} # arguments for each series minpad::Tuple # leftpad, toppad, rightpad, bottompad @@ -45,12 +45,12 @@ Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}") # ----------------------------------------------------------- # simple wrapper around a KW so we can hold all attributes pertaining to the axis in one place -type Axis +mutable struct Axis sps::Vector{Subplot} d::KW end -type Extrema +mutable struct Extrema emin::Float64 emax::Float64 end @@ -63,7 +63,7 @@ const SubplotMap = Dict{Any, Subplot} # ----------------------------------------------------------- -type Plot{T<:AbstractBackend} <: AbstractPlot{T} +mutable struct Plot{T<:AbstractBackend} <: AbstractPlot{T} backend::T # the backend type n::Int # number of series attr::KW # arguments for the whole plot diff --git a/src/utils.jl b/src/utils.jl index 65142bfc..81cd3571 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -114,7 +114,7 @@ function regressionXY(x, y) regx, regy end -function replace_image_with_heatmap{T<:Colorant}(z::Array{T}) +function replace_image_with_heatmap(z::Array{T}) where T<:Colorant @show T, size(z) n, m = size(z) # idx = 0 @@ -138,14 +138,14 @@ end # --------------------------------------------------------------- "Build line segments for plotting" -type Segments{T} +mutable struct Segments{T} pts::Vector{T} end # Segments() = Segments{Float64}(zeros(0)) Segments() = Segments(Float64) -Segments{T}(::Type{T}) = Segments(T[]) +Segments(::Type{T}) where {T} = Segments(T[]) Segments(p::Int) = Segments(NTuple{2,Float64}[]) @@ -157,7 +157,7 @@ to_nan(::Type{NTuple{2,Float64}}) = (NaN, NaN) coords(segs::Segments{Float64}) = segs.pts coords(segs::Segments{NTuple{2,Float64}}) = Float64[p[1] for p in segs.pts], Float64[p[2] for p in segs.pts] -function Base.push!{T}(segments::Segments{T}, vs...) +function Base.push!(segments::Segments{T}, vs...) where T if !isempty(segments.pts) push!(segments.pts, to_nan(T)) end @@ -167,7 +167,7 @@ function Base.push!{T}(segments::Segments{T}, vs...) segments end -function Base.push!{T}(segments::Segments{T}, vs::AVec) +function Base.push!(segments::Segments{T}, vs::AVec) where T if !isempty(segments.pts) push!(segments.pts, to_nan(T)) end @@ -181,7 +181,7 @@ end # ----------------------------------------------------- # helper to manage NaN-separated segments -type SegmentsIterator +mutable struct SegmentsIterator args::Tuple n::Int end @@ -232,8 +232,8 @@ end # Find minimal type that can contain NaN and x # To allow use of NaN separated segments with categorical x axis -float_extended_type{T}(x::AbstractArray{T}) = Union{T,Float64} -float_extended_type{T<:Real}(x::AbstractArray{T}) = Float64 +float_extended_type(x::AbstractArray{T}) where {T} = Union{T,Float64} +float_extended_type(x::AbstractArray{T}) where {T<:Real} = Float64 # ------------------------------------------------------------------------------------ @@ -259,27 +259,27 @@ _cycle(grad::ColorGradient, idx::Int) = _cycle(grad.colors, idx) _cycle(grad::ColorGradient, indices::AVec{Int}) = _cycle(grad.colors, indices) makevec(v::AVec) = v -makevec{T}(v::T) = T[v] +makevec(v::T) where {T} = T[v] "duplicate a single value, or pass the 2-tuple through" maketuple(x::Real) = (x,x) -maketuple{T,S}(x::Tuple{T,S}) = x +maketuple(x::Tuple{T,S}) where {T,S} = x mapFuncOrFuncs(f::Function, u::AVec) = map(f, u) -mapFuncOrFuncs{F<:Function}(fs::AVec{F}, u::AVec) = [map(f, u) for f in fs] +mapFuncOrFuncs(fs::AVec{F}, u::AVec) where {F<:Function} = [map(f, u) for f in fs] -unzip{X,Y}(xy::AVec{Tuple{X,Y}}) = [t[1] for t in xy], [t[2] for t in xy] -unzip{X,Y,Z}(xyz::AVec{Tuple{X,Y,Z}}) = [t[1] for t in xyz], [t[2] for t in xyz], [t[3] for t in xyz] -unzip{X,Y,U,V}(xyuv::AVec{Tuple{X,Y,U,V}}) = [t[1] for t in xyuv], [t[2] for t in xyuv], [t[3] for t in xyuv], [t[4] for t in xyuv] +unzip(xy::AVec{Tuple{X,Y}}) where {X,Y} = [t[1] for t in xy], [t[2] for t in xy] +unzip(xyz::AVec{Tuple{X,Y,Z}}) where {X,Y,Z} = [t[1] for t in xyz], [t[2] for t in xyz], [t[3] for t in xyz] +unzip(xyuv::AVec{Tuple{X,Y,U,V}}) where {X,Y,U,V} = [t[1] for t in xyuv], [t[2] for t in xyuv], [t[3] for t in xyuv], [t[4] for t in xyuv] -unzip{T}(xy::AVec{FixedSizeArrays.Vec{2,T}}) = T[t[1] for t in xy], T[t[2] for t in xy] -unzip{T}(xy::FixedSizeArrays.Vec{2,T}) = T[xy[1]], T[xy[2]] +unzip(xy::AVec{FixedSizeArrays.Vec{2,T}}) where {T} = T[t[1] for t in xy], T[t[2] for t in xy] +unzip(xy::FixedSizeArrays.Vec{2,T}) where {T} = T[xy[1]], T[xy[2]] -unzip{T}(xyz::AVec{FixedSizeArrays.Vec{3,T}}) = T[t[1] for t in xyz], T[t[2] for t in xyz], T[t[3] for t in xyz] -unzip{T}(xyz::FixedSizeArrays.Vec{3,T}) = T[xyz[1]], T[xyz[2]], T[xyz[3]] +unzip(xyz::AVec{FixedSizeArrays.Vec{3,T}}) where {T} = T[t[1] for t in xyz], T[t[2] for t in xyz], T[t[3] for t in xyz] +unzip(xyz::FixedSizeArrays.Vec{3,T}) where {T} = T[xyz[1]], T[xyz[2]], T[xyz[3]] -unzip{T}(xyuv::AVec{FixedSizeArrays.Vec{4,T}}) = T[t[1] for t in xyuv], T[t[2] for t in xyuv], T[t[3] for t in xyuv], T[t[4] for t in xyuv] -unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[3]], T[xyuv[4]] +unzip(xyuv::AVec{FixedSizeArrays.Vec{4,T}}) where {T} = T[t[1] for t in xyuv], T[t[2] for t in xyuv], T[t[3] for t in xyuv], T[t[4] for t in xyuv] +unzip(xyuv::FixedSizeArrays.Vec{4,T}) where {T} = T[xyuv[1]], T[xyuv[2]], T[xyuv[3]], T[xyuv[4]] # given 2-element lims and a vector of data x, widen lims to account for the extrema of x function _expand_limits(lims, x) @@ -388,7 +388,7 @@ isatom() = isdefined(Main, :Atom) && Main.Atom.isconnected() function is_installed(pkgstr::AbstractString) try - Pkg.installed(pkgstr) === nothing ? false: true + Pkg.installed(pkgstr) === nothing ? false : true catch false end @@ -410,20 +410,20 @@ isvertical(d::KW) = get(d, :orientation, :vertical) in (:vertical, :v, :vert) isvertical(series::Series) = isvertical(series.d) -ticksType{T<:Real}(ticks::AVec{T}) = :ticks -ticksType{T<:AbstractString}(ticks::AVec{T}) = :labels -ticksType{T<:AVec,S<:AVec}(ticks::Tuple{T,S}) = :ticks_and_labels +ticksType(ticks::AVec{T}) where {T<:Real} = :ticks +ticksType(ticks::AVec{T}) where {T<:AbstractString} = :labels +ticksType(ticks::Tuple{T,S}) where {T<:AVec,S<:AVec} = :ticks_and_labels ticksType(ticks) = :invalid -limsType{T<:Real,S<:Real}(lims::Tuple{T,S}) = :limits +limsType(lims::Tuple{T,S}) where {T<:Real,S<:Real} = :limits limsType(lims::Symbol) = lims == :auto ? :auto : :invalid limsType(lims) = :invalid # axis_Symbol(letter, postfix) = Symbol(letter * postfix) # axis_symbols(letter, postfix...) = map(s -> axis_Symbol(letter, s), postfix) -Base.convert{T<:Real}(::Type{Vector{T}}, rng::Range{T}) = T[x for x in rng] -Base.convert{T<:Real,S<:Real}(::Type{Vector{T}}, rng::Range{S}) = T[x for x in rng] +Base.convert(::Type{Vector{T}}, rng::Range{T}) where {T<:Real} = T[x for x in rng] +Base.convert(::Type{Vector{T}}, rng::Range{S}) where {T<:Real,S<:Real} = T[x for x in rng] Base.merge(a::AbstractVector, b::AbstractVector) = sort(unique(vcat(a,b))) @@ -727,7 +727,7 @@ end # --------------------------------------------------------------- # --------------------------------------------------------------- -type DebugMode +mutable struct DebugMode on::Bool end const _debugMode = DebugMode(false) @@ -765,10 +765,10 @@ end extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignorenan_maximum(v)) -extendSeriesData{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z) -extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z) -extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v) -extendSeriesData{T}(v::AVec{T}, z::AVec) = (append!(v, convert(Vector{T}, z)); v) +extendSeriesData(v::Range{T}, z::Real) where {T} = extendSeriesData(float(collect(v)), z) +extendSeriesData(v::Range{T}, z::AVec) where {T} = extendSeriesData(float(collect(v)), z) +extendSeriesData(v::AVec{T}, z::Real) where {T} = (push!(v, convert(T, z)); v) +extendSeriesData(v::AVec{T}, z::AVec) where {T} = (append!(v, convert(Vector{T}, z)); v) # ------------------------------------------------------- @@ -786,14 +786,14 @@ function getxyz(plt::Plot, i::Integer) tovec(d[:x]), tovec(d[:y]), tovec(d[:z]) end -function setxy!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) +function setxy!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y} series = plt.series_list[i] series.d[:x], series.d[:y] = xy sp = series.d[:subplot] reset_extrema!(sp) _series_updated(plt, series) end -function setxyz!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) +function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z} series = plt.series_list[i] series.d[:x], series.d[:y], series.d[:z] = xyz sp = series.d[:subplot] @@ -801,7 +801,7 @@ function setxyz!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) _series_updated(plt, series) end -function setxyz!{X,Y,Z<:AbstractMatrix}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) +function setxyz!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z<:AbstractMatrix} setxyz!(plt, (xyz[1], xyz[2], Surface(xyz[3])), i) end @@ -810,8 +810,8 @@ end # indexing notation # Base.getindex(plt::Plot, i::Integer) = getxy(plt, i) -Base.setindex!{X,Y}(plt::Plot, xy::Tuple{X,Y}, i::Integer) = (setxy!(plt, xy, i); plt) -Base.setindex!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) = (setxyz!(plt, xyz, i); plt) +Base.setindex!(plt::Plot, xy::Tuple{X,Y}, i::Integer) where {X,Y} = (setxy!(plt, xy, i); plt) +Base.setindex!(plt::Plot, xyz::Tuple{X,Y,Z}, i::Integer) where {X,Y,Z} = (setxyz!(plt, xyz, i); plt) # ------------------------------------------------------- @@ -923,10 +923,10 @@ function Base.append!(plt::Plot, i::Integer, x::AVec, y::AVec, z::AVec) end # tuples -Base.push!{X,Y}(plt::Plot, xy::Tuple{X,Y}) = push!(plt, 1, xy...) -Base.push!{X,Y,Z}(plt::Plot, xyz::Tuple{X,Y,Z}) = push!(plt, 1, xyz...) -Base.push!{X,Y}(plt::Plot, i::Integer, xy::Tuple{X,Y}) = push!(plt, i, xy...) -Base.push!{X,Y,Z}(plt::Plot, i::Integer, xyz::Tuple{X,Y,Z}) = push!(plt, i, xyz...) +Base.push!(plt::Plot, xy::Tuple{X,Y}) where {X,Y} = push!(plt, 1, xy...) +Base.push!(plt::Plot, xyz::Tuple{X,Y,Z}) where {X,Y,Z} = push!(plt, 1, xyz...) +Base.push!(plt::Plot, i::Integer, xy::Tuple{X,Y}) where {X,Y} = push!(plt, i, xy...) +Base.push!(plt::Plot, i::Integer, xyz::Tuple{X,Y,Z}) where {X,Y,Z} = push!(plt, i, xyz...) # ------------------------------------------------------- # push/append for all series From c76fc5b9096a700f1d5a3c597ebdd525b754aa72 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 18 Oct 2017 20:47:06 +0200 Subject: [PATCH 055/115] use fg_color for matrices with unique non-zeros in spy recipe --- src/recipes.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 6e49fb03..bae34819 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -937,8 +937,7 @@ end mat = g.args[1] if length(unique(mat[mat .!= 0])) < 2 legend --> nothing - # revert the default gradient to have a darker (almost black) color in the default theme - seriescolor --> cgrad([cgrad()[0], cgrad()[1]]) + seriescolor --> cgrad([invisible(), fg_color(plotattributes)]) end n,m = size(mat) Plots.SliceIt, 1:m, 1:n, Surface(mat) From e78bf87377cbf5cac4f5808f9e964eb0bc77fda0 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 18 Oct 2017 20:24:07 +0200 Subject: [PATCH 056/115] update some test_examples --- src/examples.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/examples.jl b/src/examples.jl index 3f8acaa3..6d1f1589 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -262,7 +262,8 @@ PlotExample("Groups and Subplots", "", [:(begin group = rand(map(i->"group $i",1:4),100) - plot(rand(100), layout=@layout([a b;c]), group=group, linetype=[:bar :scatter :steppre]) + plot(rand(100), layout=@layout([a b;c]), group=group, + linetype=[:bar :scatter :steppre], linewidth = [0 0 1]) end)] ), @@ -322,11 +323,11 @@ 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`.", [:(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)) - plot(spy(a, markershape = :dtriangle), spy(b), markersize = 3, title = ["Unique nonzeros" "Different nonzeros"]) + plot(spy(a), spy(b), title = ["Unique nonzeros" "Different nonzeros"]) end)] ), @@ -345,8 +346,10 @@ PlotExample("Magic grid argument", 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 = "") + scatter(fill(randn(10), 7), fill(randn(10), 7), + framestyle = [:box :semi :origin :zerolines :grid :none], + title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"], + color = RowVector(1:7), layout = 7, label = "", markerstrokewidth = 0) end)] ), From 6d4f4568261fc8401cde709addaafbe9a64d8c0d Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 18 Oct 2017 21:06:37 +0200 Subject: [PATCH 057/115] fix framestyle testexample --- src/examples.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/examples.jl b/src/examples.jl index 6d1f1589..3e4868b6 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -346,10 +346,10 @@ PlotExample("Magic grid argument", 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 - scatter(fill(randn(10), 7), fill(randn(10), 7), + scatter(fill(randn(10), 6), fill(randn(10), 6), framestyle = [:box :semi :origin :zerolines :grid :none], title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"], - color = RowVector(1:7), layout = 7, label = "", markerstrokewidth = 0) + color = RowVector(1:6), layout = 6, label = "", markerstrokewidth = 0) end)] ), From 7ffd1fc9c208fc53dba10d46df941b11a6aa6f98 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 18 Oct 2017 21:24:28 +0200 Subject: [PATCH 058/115] some further improvements for framestyle and group testexamples --- src/examples.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/examples.jl b/src/examples.jl index 3e4868b6..b3ac5f6b 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -263,7 +263,7 @@ PlotExample("Groups and Subplots", [:(begin group = rand(map(i->"group $i",1:4),100) plot(rand(100), layout=@layout([a b;c]), group=group, - linetype=[:bar :scatter :steppre], linewidth = [0 0 1]) + linetype=[:bar :scatter :steppre], linecolor = :match) end)] ), @@ -349,7 +349,8 @@ PlotExample("Framestyle", scatter(fill(randn(10), 6), fill(randn(10), 6), framestyle = [:box :semi :origin :zerolines :grid :none], title = [":box" ":semi" ":origin" ":zerolines" ":grid" ":none"], - color = RowVector(1:6), layout = 6, label = "", markerstrokewidth = 0) + color = RowVector(1:6), layout = 6, label = "", markerstrokewidth = 0, + ticks = -2:2) end)] ), From 0c4750547ab2c4b22838e3a710197067bdaf5ce4 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Thu, 19 Oct 2017 15:29:52 +0100 Subject: [PATCH 059/115] Fix LaTeX error for log scale ticks. --- src/backends/pgfplots.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index a5f1a1b0..10eb63de 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -300,7 +300,15 @@ function pgf_axis(sp::Subplot, letter) if !(axis[:ticks] in (nothing, false, :none)) && framestyle != :none ticks = get_ticks(axis) push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) - if axis[:showaxis] + if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto + # wrap the power part of label with } + tick_labels = String[begin + base, power = split(label, "^") + power = string("{", power, "}") + string(base, "^", power) + end for label in ticks[2]] + push!(style, string(letter, "ticklabels = {\$", join(tick_labels,"\$,\$"), "\$}")) + elseif axis[:showaxis] push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) else push!(style, string(letter, "ticklabels = {}")) From cdcbdc308c1a3cec3792986ef2cd8c2680f398c8 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Wed, 13 Sep 2017 22:14:59 +0200 Subject: [PATCH 060/115] include backend files --- src/Plots.jl | 2 ++ src/backends/glvisualize.jl | 4 ++++ src/backends/gr.jl | 3 +++ src/backends/hdf5.jl | 5 ++++- src/backends/inspectdr.jl | 4 ++++ src/backends/pgfplots.jl | 4 ++++ src/backends/plotly.jl | 4 ++++ src/backends/plotlyjs.jl | 3 +++ src/backends/pyplot.jl | 3 +++ src/backends/unicodeplots.jl | 4 ++++ src/backends/web.jl | 4 +++- src/output.jl | 1 - 12 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index d4f05cc5..51d70256 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -15,6 +15,8 @@ using Base.Meta import Showoff import StatsBase +using Requires + export grid, bbox, diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 716ce78a..924eca72 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -9,6 +9,10 @@ TODO * fix units in all visuals (e.g dotted lines, marker scale, surfaces) =# +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) +end + const _glvisualize_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 791055ed..facfeb7f 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -3,6 +3,9 @@ # significant contributions by @jheinen +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) +end const _gr_attr = merge_with_base_supported([ :annotations, diff --git a/src/backends/hdf5.jl b/src/backends/hdf5.jl index 3adc912a..3e5afa87 100644 --- a/src/backends/hdf5.jl +++ b/src/backends/hdf5.jl @@ -28,6 +28,9 @@ Read from .hdf5 file using: - Should be reliable for archival purposes. ==# +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "hdf5.jl")) +end import FixedPointNumbers: N0f8 #In core Julia @@ -128,7 +131,7 @@ function _hdf5_merge!(dest::Dict, src::Dict) _hdf5_merge!(dest[k].d, v.d) else dest[k] = v - end + end end return end diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 65f019a0..da7bc144 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -13,6 +13,10 @@ Add in functionality to Plots.jl: :aspect_ratio, =# +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) +end + # --------------------------------------------------------------------------- #TODO: remove features const _inspectdr_attr = merge_with_base_supported([ diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 10eb63de..2ae69b3f 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -2,6 +2,10 @@ # significant contributions by: @pkofod +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pgfplots.jl")) +end + const _pgfplots_attr = merge_with_base_supported([ :annotations, # :background_color_legend, diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index f5ee90fa..d74357e7 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -1,6 +1,10 @@ # https://plot.ly/javascript/getting-started +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) +end + const _plotly_attr = merge_with_base_supported([ :annotations, :background_color_legend, :background_color_inside, :background_color_outside, diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 0776dbf1..1bcc3845 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -1,3 +1,6 @@ +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotlyjs.jl")) +end # https://github.com/spencerlyon2/PlotlyJS.jl diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index e3b70eb9..4a8c3c95 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1,6 +1,9 @@ # https://github.com/stevengj/PyPlot.jl +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) +end const _pyplot_attr = merge_with_base_supported([ :annotations, diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index f5e34834..99482750 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -1,6 +1,10 @@ # https://github.com/Evizero/UnicodePlots.jl +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "unicodeplots.jl")) +end + const _unicodeplots_attr = merge_with_base_supported([ :label, :legend, diff --git a/src/backends/web.jl b/src/backends/web.jl index b0be7a3e..36fd5d06 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -2,7 +2,9 @@ # NOTE: backend should implement `html_body` and `html_head` # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl - +@require Revise begin + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl")) +end function standalone_html(plt::AbstractPlot; title::AbstractString = get(plt.attr, :window_title, "Plots.jl")) """ diff --git a/src/output.jl b/src/output.jl index 37849d8b..88caeeee 100644 --- a/src/output.jl +++ b/src/output.jl @@ -258,7 +258,6 @@ end const _ijulia_output = String["text/html"] -using Requires @require IJulia begin if IJulia.inited export set_ijulia_output From 133052b58c45da62119c56c85138dd9b2abe0486 Mon Sep 17 00:00:00 2001 From: Andy Nowacki Date: Thu, 19 Oct 2017 11:23:23 +0100 Subject: [PATCH 061/115] Animations: improve movie compatibility when using ffmpeg Add the -pix_fmt yuv420p option when using ffmpeg to save animations with the mov or mp4 commands. This improves compatibility of the movie files since many players do not support the ffmpeg defaults. To do this, add a third positional argument to `buildanimation` to specify if we want an animated GIF file. The default is `true`. See the following for more information: - https://trac.ffmpeg.org/wiki/Encode/H.264 ('Compatibility') - https://apple.stackexchange.com/questions/166553/why-wont-video-from-ffmpeg-show-in-quicktime-imovie-or-quick-preview --- src/animation.jl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 0f539b01..8d3c0341 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -61,18 +61,23 @@ end file_extension(fn) = Base.Filesystem.splitext(fn)[2][2:end] gif(anim::Animation, fn = giffn(); kw...) = buildanimation(anim.dir, fn; kw...) -mov(anim::Animation, fn = movfn(); kw...) = buildanimation(anim.dir, fn; kw...) -mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim.dir, fn; kw...) +mov(anim::Animation, fn = movfn(); kw...) = buildanimation(anim.dir, fn, false; kw...) +mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim.dir, fn, false; kw...) -function buildanimation(animdir::AbstractString, fn::AbstractString; +function buildanimation(animdir::AbstractString, fn::AbstractString, + is_animated_gif::Bool=true; fps::Integer = 20, loop::Integer = 0) fn = abspath(fn) - # generate a colorpalette first so ffmpeg does not have to guess it - run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.png`) - # then apply the palette to get better results - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.png -lavfi paletteuse -y $fn`) + if is_animated_gif + # generate a colorpalette first so ffmpeg does not have to guess it + run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.png`) + # then apply the palette to get better results + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.png -lavfi paletteuse -y $fn`) + else + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -pix_fmt yuv420p -y $fn`) + end info("Saved animation to ", fn) AnimatedGif(fn) From ad6b707abfd0528a17ba7a3d2de16bc7fffdd121 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Tue, 24 Oct 2017 19:50:18 +0200 Subject: [PATCH 062/115] gr: implement title location --- src/backends/gr.jl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index facfeb7f..ef539066 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -863,9 +863,20 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.savestate() if sp[:title] != "" gr_set_font(sp[:titlefont]) - GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) + loc = sp[:title_location] + if loc == :left + xpos = viewport_plotarea[1] + halign = GR.TEXT_HALIGN_LEFT + elseif loc == :right + xpos = viewport_plotarea[2] + halign = GR.TEXT_HALIGN_RIGHT + else + xpos = gr_view_xcenter() + halign = GR.TEXT_HALIGN_CENTER + end + GR.settextalign(halign, GR.TEXT_VALIGN_TOP) gr_set_textcolor(sp[:foreground_color_title]) - gr_text(gr_view_xcenter(), viewport_subplot[4], sp[:title]) + gr_text(xpos, viewport_subplot[4], sp[:title]) end if xaxis[:guide] != "" From 7b6b44b2847029dbe6e8f9bf3fd2872a31d159ea Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Fri, 27 Oct 2017 15:52:32 +0200 Subject: [PATCH 063/115] add hline to pgfplots --- src/backends/pgfplots.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 2ae69b3f..ef009fe1 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -41,7 +41,7 @@ const _pgfplots_attr = merge_with_base_supported([ ]) const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] -const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon] #vcat(_allMarkers, Shape) +const _pgfplots_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5, :pentagon, :hline] #vcat(_allMarkers, Shape) const _pgfplots_scale = [:identity, :ln, :log2, :log10] @@ -86,6 +86,7 @@ const _pgfplots_markers = KW( :star6 => "asterisk", :diamond => "diamond*", :pentagon => "pentagon*", + :hline => "-" ) const _pgfplots_legend_pos = KW( From 5a3779e431ff5557dce6461e90ec68d05b4d65d9 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 30 Oct 2017 10:49:22 +0100 Subject: [PATCH 064/115] fill = true fills to 0 --- src/args.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/args.jl b/src/args.jl index 81cf03f8..afef5aeb 100644 --- a/src/args.jl +++ b/src/args.jl @@ -695,6 +695,9 @@ function processFillArg(d::KW, arg) arg.color == nothing || (d[:fillcolor] = arg.color == :auto ? :auto : plot_color(arg.color)) arg.alpha == nothing || (d[:fillalpha] = arg.alpha) + elseif typeof(arg) <: Bool + d[:fillrange] = arg ? 0 : nothing + # fillrange function elseif allFunctions(arg) d[:fillrange] = arg From a3e599e38d842919a1ee12508fdc396ca40f14ac Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Mon, 30 Oct 2017 19:50:02 +0000 Subject: [PATCH 065/115] Fix colorbar always displaying in Plotly. --- src/backends/plotly.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index d74357e7..b15e82c0 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -526,7 +526,7 @@ function plotly_series(plt::Plot, series::Series) d_out[:type] = "heatmap" # d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha]) - d_out[:showscale] = sp[:legend] != :none + d_out[:showscale] = hascolorbar(sp) elseif st == :contour d_out[:type] = "contour" @@ -535,7 +535,7 @@ function plotly_series(plt::Plot, series::Series) d_out[:ncontours] = series[:levels] d_out[:contours] = KW(:coloring => series[:fillrange] != nothing ? "fill" : "lines") d_out[:colorscale] = plotly_colorscale(series[:linecolor], series[:linealpha]) - d_out[:showscale] = sp[:legend] != :none + d_out[:showscale] = hascolorbar(sp) elseif st in (:surface, :wireframe) d_out[:type] = "surface" @@ -555,7 +555,7 @@ function plotly_series(plt::Plot, series::Series) if series[:fill_z] != nothing d_out[:surfacecolor] = plotly_surface_data(series, series[:fill_z]) end - d_out[:showscale] = sp[:legend] != :none + d_out[:showscale] = hascolorbar(sp) end elseif st == :pie From 4f171e3eb540e8fca41246708c3f88bb06550645 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Thu, 2 Nov 2017 16:32:57 +0000 Subject: [PATCH 066/115] Add handling of polar axes. --- src/axes.jl | 20 +++++++++++++++++--- src/backends/pgfplots.jl | 7 +++++-- src/backends/plotly.jl | 19 +++++++++++++++++++ src/backends/pyplot.jl | 5 +++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 4288cde3..7ca04d2b 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -239,8 +239,13 @@ function get_ticks(axis::Axis) # discrete ticks... axis[:continuous_values], dvals elseif ticks == :auto - # compute optimal ticks and labels - optimal_ticks_and_labels(axis) + if ispolar(axis.sps[1]) && axis[:letter] == :x + #force theta axis to be full circle + (collect(0:pi/4:7pi/4), string.(0:45:315)) + else + # compute optimal ticks and labels + optimal_ticks_and_labels(axis) + end elseif typeof(ticks) <: Union{AVec, Int} # override ticks, but get the labels optimal_ticks_and_labels(axis, ticks) @@ -427,7 +432,16 @@ function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis) if !isfinite(amin) && !isfinite(amax) amin, amax = 0.0, 1.0 end - if should_widen + if ispolar(axis.sps[1]) + if axis[:letter] == :x + amin, amax = 0, 2pi + elseif lims == :auto + #widen max radius so ticks dont overlap with theta axis + amin, 1.1*amax + else + amin, amax + end + elseif should_widen widen(amin, amax) else amin, amax diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index ef009fe1..5f73a674 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -220,6 +220,8 @@ function pgf_series(sp::Subplot, series::Series) # If a marker_z is used pass it as third coordinate to a 2D plot. # See "Scatter Plots" in PGFPlots documentation d[:x], d[:y], d[:marker_z] + elseif ispolar(sp) + rad2deg.(d[:x]), d[:y] else d[:x], d[:y] end @@ -297,14 +299,15 @@ function pgf_axis(sp::Subplot, letter) # limits # TODO: support zlims if letter != :z - lims = axis_limits(axis) + lims = ispolar(sp) && letter == :x ? rad2deg.(axis_limits(axis)) : axis_limits(axis) kw[Symbol(letter,:min)] = lims[1] kw[Symbol(letter,:max)] = lims[2] end if !(axis[:ticks] in (nothing, false, :none)) && framestyle != :none ticks = get_ticks(axis) - push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) + tick_values = ispolar(sp) && letter == :x ? rad2deg.(ticks[1]) : ticks[1] + push!(style, string(letter, "tick = {", join(tick_values,","), "}")) if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto # wrap the power part of label with } tick_labels = String[begin diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b15e82c0..e06f4151 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -291,6 +291,22 @@ function plotly_axis(axis::Axis, sp::Subplot) ax end +function plotly_polaraxis(axis::Axis) + ax = KW( + :visible => axis[:grid], + :showline => axis[:grid], + ) + + if axis[:letter] == :x + ax[:range] = rad2deg.(axis_limits(axis)) + else + ax[:range] = axis_limits(axis) + ax[:orientation] = 0 + end + + ax +end + function plotly_layout(plt::Plot) d_out = KW() @@ -345,6 +361,9 @@ function plotly_layout(plt::Plot) ), ), ) + elseif ispolar(sp) + d_out[Symbol("angularaxis$spidx")] = plotly_polaraxis(sp[:xaxis]) + d_out[Symbol("radialaxis$spidx")] = plotly_polaraxis(sp[:yaxis]) else d_out[Symbol("xaxis$spidx")] = plotly_axis(sp[:xaxis], sp) d_out[Symbol("yaxis$spidx")] = plotly_axis(sp[:yaxis], sp) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 4a8c3c95..9022a692 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1054,6 +1054,9 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) end py_set_scale(ax, axis) py_set_lims(ax, axis) + if ispolar(sp) && letter == :y + ax[:set_rlabel_position](0) + end ticks = sp[:framestyle] == :none ? nothing : get_ticks(axis) # don't show the 0 tick label for the origin framestyle if sp[:framestyle] == :origin && length(ticks) > 1 @@ -1080,6 +1083,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) linewidth = axis[:gridlinewidth], alpha = axis[:gridalpha]) ax[:set_axisbelow](true) + else + pyaxis[:grid](false) end py_set_axis_colors(sp, ax, axis) end From 12aa43ff5f2239e02d038695c0729b86e868e04b Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Thu, 2 Nov 2017 16:33:05 +0000 Subject: [PATCH 067/115] Fix deprecations. --- src/backends/inspectdr.jl | 2 +- src/backends/plotly.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index da7bc144..7d09045a 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -245,7 +245,7 @@ function _series_added(plt::Plot{InspectDRBackend}, series::Series) #No support for polar grid... but can still perform polar transformation: if ispolar(sp) Θ = x; r = y - x = r.*cos(Θ); y = r.*sin(Θ) + x = r.*cos.(Θ); y = r.*sin.(Θ) end # doesn't handle mismatched x/y - wrap data (pyplot behaviour): diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index e06f4151..96c54c9c 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -717,7 +717,7 @@ end function plotly_polar!(d_out::KW, series::Series) # convert polar plots x/y to theta/radius if ispolar(series[:subplot]) - d_out[:t] = rad2deg(pop!(d_out, :x)) + d_out[:t] = rad2deg.(pop!(d_out, :x)) d_out[:r] = pop!(d_out, :y) end end From f690961af2435c84e041163ed6a2217e973d3933 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Thu, 2 Nov 2017 20:12:11 +0100 Subject: [PATCH 068/115] gr: use correct aspect ratio (fixes #1219) --- src/backends/gr.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ef539066..95dfcbde 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -412,6 +412,9 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi viewport[3] = 0.5 * (vp[3] + vp[4] - extent) viewport[4] = 0.5 * (vp[3] + vp[4] + extent) end + if hascolorbar(sp) + viewport[2] -= (viewport[2] - viewport[1]) * 0.1 + end viewport end @@ -687,11 +690,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end end - if cmap - # note: add extra midpadding on the right for the colorbar - viewport_plotarea[2] -= 0.1 - end - # set our plot area view gr_set_viewport_plotarea() From 5d5d8f073ae7c38d9a7b16e56e427c743706d297 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 2 Nov 2017 20:38:06 +0100 Subject: [PATCH 069/115] allow setting the linewidth for contour plots in GR --- 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 ef539066..dfc726bd 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -4,7 +4,7 @@ # significant contributions by @jheinen @require Revise begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "gr.jl")) end const _gr_attr = merge_with_base_supported([ @@ -997,11 +997,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if series[:fillrange] != nothing GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) else + GR.setlinewidth(series[:linewidth]) GR.contour(x, y, h, z, 1000) end # create the colorbar of contour levels if cmap + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) gr_set_viewport_cmap(sp) l = round.(Int32, 1000 + (h - ignorenan_minimum(h)) / (ignorenan_maximum(h) - ignorenan_minimum(h)) * 255) GR.setwindow(xmin, xmax, zmin, zmax) From b34f4141a2c25581aa248c702890b6cb62c89739 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Thu, 2 Nov 2017 21:53:11 +0100 Subject: [PATCH 070/115] Update gr.jl --- 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 95dfcbde..359f2727 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -413,7 +413,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi viewport[4] = 0.5 * (vp[3] + vp[4] + extent) end if hascolorbar(sp) - viewport[2] -= (viewport[2] - viewport[1]) * 0.1 + viewport[2] -= 0.1 end viewport end From 40282ae23ab55480b2acfe9e0d1465c7e6539b67 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 3 Nov 2017 10:02:16 +0100 Subject: [PATCH 071/115] allow setting the linestyle for contours on GR --- 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 dfc726bd..9fc65c27 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -997,7 +997,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if series[:fillrange] != nothing GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) else - GR.setlinewidth(series[:linewidth]) + GR.setlinetype(gr_linetype[series[:linestyle]]) + width, height = gr_plot_size + GR.setlinewidth(max(0, series[:linewidth] / (sum(gr_plot_size) * 0.001))) GR.contour(x, y, h, z, 1000) end From 8dd264c4da66170043be667882ad0e8ba0dcc60f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 3 Nov 2017 10:15:55 +0100 Subject: [PATCH 072/115] remove unnecessary line --- src/backends/gr.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9fc65c27..7df19ff0 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -998,7 +998,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.surface(x, y, z, GR.OPTION_CELL_ARRAY) else GR.setlinetype(gr_linetype[series[:linestyle]]) - width, height = gr_plot_size GR.setlinewidth(max(0, series[:linewidth] / (sum(gr_plot_size) * 0.001))) GR.contour(x, y, h, z, 1000) end From f0ad851aa7a7c47d490073e552a4637dfe12d755 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Fri, 3 Nov 2017 19:45:17 +0000 Subject: [PATCH 073/115] Make radial axis vertical. --- src/backends/pgfplots.jl | 9 +++++++-- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 5f73a674..e0f35f4d 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -306,7 +306,8 @@ function pgf_axis(sp::Subplot, letter) if !(axis[:ticks] in (nothing, false, :none)) && framestyle != :none ticks = get_ticks(axis) - tick_values = ispolar(sp) && letter == :x ? rad2deg.(ticks[1]) : ticks[1] + #pgf plot ignores ticks with angle below 90 when xmin = 90 so shift values + tick_values = ispolar(sp) && letter == :x ? [rad2deg.(ticks[1])[3:end]..., 360, 415] : ticks[1] push!(style, string(letter, "tick = {", join(tick_values,","), "}")) if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto # wrap the power part of label with } @@ -317,7 +318,8 @@ function pgf_axis(sp::Subplot, letter) end for label in ticks[2]] push!(style, string(letter, "ticklabels = {\$", join(tick_labels,"\$,\$"), "\$}")) elseif axis[:showaxis] - push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) + tick_labels = ispolar(sp) && letter == :x ? [ticks[2][3:end]..., "0", "45"] : ticks[2] + push!(style, string(letter, "ticklabels = {", join(tick_labels,","), "}")) else push!(style, string(letter, "ticklabels = {}")) end @@ -405,6 +407,9 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend}) axisf = PGFPlots.Axis if sp[:projection] == :polar axisf = PGFPlots.PolarAxis + #make radial axis vertical + kw[:xmin] = 90 + kw[:xmax] = 450 end # Search series for any gradient. In case one series uses a gradient set diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 96c54c9c..940e36f6 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -301,7 +301,7 @@ function plotly_polaraxis(axis::Axis) ax[:range] = rad2deg.(axis_limits(axis)) else ax[:range] = axis_limits(axis) - ax[:orientation] = 0 + ax[:orientation] = -90 end ax diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 9022a692..86a8b5a0 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1055,7 +1055,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) py_set_scale(ax, axis) py_set_lims(ax, axis) if ispolar(sp) && letter == :y - ax[:set_rlabel_position](0) + ax[:set_rlabel_position](90) end ticks = sp[:framestyle] == :none ? nothing : get_ticks(axis) # don't show the 0 tick label for the origin framestyle From 2fe2ff474c3871400300371847709fa9e2859a59 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 4 Nov 2017 21:27:02 +0000 Subject: [PATCH 074/115] Implement grid attributes for polar plots. --- src/backends/gr.jl | 85 +++++++++++++++++++++++++++------------- src/backends/pgfplots.jl | 2 + src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 10 ++++- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ef539066..cfb6e85d 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -205,35 +205,66 @@ function gr_text(x, y, s) end end -function gr_polaraxes(rmin, rmax) +function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) GR.savestate() - GR.setlinetype(GR.LINETYPE_SOLID) - GR.setlinecolorind(88) + xaxis = sp[:xaxis] + yaxis = sp[:yaxis] + + α = 0:45:315 + a = α .+ 90 + sinf = sind.(a) + cosf = cosd.(a) tick = 0.5 * GR.tick(rmin, rmax) n = round(Int, (rmax - rmin) / tick + 0.5) - for i in 0:n - r = float(i) / n - if i % 2 == 0 - GR.setlinecolorind(88) - if i > 0 - GR.drawarc(-r, r, -r, r, 0, 359) - end - GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) - x, y = GR.wctondc(0.05, r) - GR.text(x, y, string(signif(rmin + i * tick, 12))) - else - GR.setlinecolorind(90) - GR.drawarc(-r, r, -r, r, 0, 359) + + #draw angular grid + if xaxis[:grid] + gr_set_line(xaxis[:gridlinewidth], xaxis[:gridstyle], xaxis[:foreground_color_grid]) + GR.settransparency(xaxis[:gridalpha]) + for i in 1:length(α) + GR.polyline([sinf[i], 0], [cosf[i], 0]) end end - for α in 0:45:315 - a = α + 90 - sinf = sin(a * pi / 180) - cosf = cos(a * pi / 180) - GR.polyline([sinf, 0], [cosf, 0]) - GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF) - x, y = GR.wctondc(1.1 * sinf, 1.1 * cosf) - GR.textext(x, y, string(α, "^o")) + + #draw radial grid + if yaxis[:grid] + gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid]) + GR.settransparency(yaxis[:gridalpha]) + for i in 0:n + r = float(i) / n + if i % 2 == 0 + if i > 0 + GR.drawarc(-r, r, -r, r, 0, 359) + end + else + GR.drawarc(-r, r, -r, r, 0, 359) + end + end + end + + #prepare to draw ticks + GR.settransparency(1) + GR.setlinecolorind(90) + GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF) + + #draw angular ticks + if xaxis[:showaxis] + GR.drawarc(-1, 1, -1, 1, 0, 359) + for i in 1:length(α) + x, y = GR.wctondc(1.1 * sinf[i], 1.1 * cosf[i]) + GR.textext(x, y, string((360-α[i])%360, "^o")) + end + end + + #draw radial ticks + if yaxis[:showaxis] + for i in 0:n + r = float(i) / n + if i % 2 == 0 + x, y = GR.wctondc(0.05, r) + GR.text(x, y, string(signif(rmin + i * tick, 12))) + end + end end GR.restorestate() end @@ -760,9 +791,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif ispolar(sp) r = gr_set_viewport_polar() - rmin, rmax = GR.adjustrange(ignorenan_minimum(r), ignorenan_maximum(r)) - # rmin, rmax = axis_limits(sp[:yaxis]) - gr_polaraxes(rmin, rmax) + #rmin, rmax = GR.adjustrange(ignorenan_minimum(r), ignorenan_maximum(r)) + rmin, rmax = axis_limits(sp[:yaxis]) + gr_polaraxes(rmin, rmax, sp) elseif draw_axes if xmax > xmin && ymax > ymin diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index e0f35f4d..da527f9a 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -294,6 +294,8 @@ function pgf_axis(sp::Subplot, letter) # grid on or off if axis[:grid] && framestyle != :none push!(style, "$(letter)majorgrids = true") + else + push!(style, "$(letter)majorgrids = false") end # limits diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 940e36f6..9ada51f7 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -293,7 +293,7 @@ end function plotly_polaraxis(axis::Axis) ax = KW( - :visible => axis[:grid], + :visible => axis[:showaxis], :showline => axis[:grid], ) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 86a8b5a0..d325b21b 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1093,7 +1093,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) if !sp[:xaxis][:showaxis] kw = KW() for dir in (:top, :bottom) - ax[:spines][string(dir)][:set_visible](false) + if ispolar(sp) + ax[:spines]["polar"][:set_visible](false) + else + ax[:spines][string(dir)][:set_visible](false) + end kw[dir] = kw[Symbol(:label,dir)] = "off" end ax[:xaxis][:set_tick_params](; which="both", kw...) @@ -1101,7 +1105,9 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) if !sp[:yaxis][:showaxis] kw = KW() for dir in (:left, :right) - ax[:spines][string(dir)][:set_visible](false) + if !ispolar(sp) + ax[:spines][string(dir)][:set_visible](false) + end kw[dir] = kw[Symbol(:label,dir)] = "off" end ax[:yaxis][:set_tick_params](; which="both", kw...) From 8fb3f3b1c93f611a12ac8549cc91892a05c37251 Mon Sep 17 00:00:00 2001 From: Hessam Mehr Date: Sat, 4 Nov 2017 15:19:03 -0700 Subject: [PATCH 075/115] Fixed for #1138 --- src/backends/plotly.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b15e82c0..dc59fe5f 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -728,7 +728,7 @@ end const _use_remote = Ref(false) function html_head(plt::Plot{PlotlyBackend}) - jsfilename = _use_remote[] ? _plotly_js_path_remote : _plotly_js_path + jsfilename = _use_remote[] ? _plotly_js_path_remote : ("file://" * _plotly_js_path) # "" "" end From cc43202e8f854648cd00e498e9ffe138665c6d5f Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sat, 4 Nov 2017 23:04:49 +0000 Subject: [PATCH 076/115] Fix radial axis tick alignment for GR. --- src/backends/gr.jl | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index cfb6e85d..b31a37ca 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -231,15 +231,12 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid]) GR.settransparency(yaxis[:gridalpha]) for i in 0:n - r = float(i) / n - if i % 2 == 0 - if i > 0 - GR.drawarc(-r, r, -r, r, 0, 359) - end - else + r = float(i) * tick / rmax + if r <= 1.0 GR.drawarc(-r, r, -r, r, 0, 359) end end + GR.drawarc(-1, 1, -1, 1, 0, 359) end #prepare to draw ticks @@ -259,8 +256,8 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) #draw radial ticks if yaxis[:showaxis] for i in 0:n - r = float(i) / n - if i % 2 == 0 + r = float(i) * tick / rmax + if i % 2 == 0 && r <= 1.0 x, y = GR.wctondc(0.05, r) GR.text(x, y, string(signif(rmin + i * tick, 12))) end From 08a6f3af3659309875097cf90018f33f517dbafc Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sun, 5 Nov 2017 10:37:51 +0000 Subject: [PATCH 077/115] Allow custom radial ticks for GR. Fix polar ylims for non-zero ymin values in GR. --- src/backends/gr.jl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b31a37ca..9c21cf3e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -214,8 +214,7 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) a = α .+ 90 sinf = sind.(a) cosf = cosd.(a) - tick = 0.5 * GR.tick(rmin, rmax) - n = round(Int, (rmax - rmin) / tick + 0.5) + rtick_values, rtick_labels = get_ticks(yaxis) #draw angular grid if xaxis[:grid] @@ -230,9 +229,9 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) if yaxis[:grid] gr_set_line(yaxis[:gridlinewidth], yaxis[:gridstyle], yaxis[:foreground_color_grid]) GR.settransparency(yaxis[:gridalpha]) - for i in 0:n - r = float(i) * tick / rmax - if r <= 1.0 + for i in 1:length(rtick_values) + r = (rtick_values[i] - rmin) / (rmax - rmin) + if r <= 1.0 && r >= 0.0 GR.drawarc(-r, r, -r, r, 0, 359) end end @@ -255,11 +254,11 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot) #draw radial ticks if yaxis[:showaxis] - for i in 0:n - r = float(i) * tick / rmax - if i % 2 == 0 && r <= 1.0 + for i in 1:length(rtick_values) + r = (rtick_values[i] - rmin) / (rmax - rmin) + if r <= 1.0 && r >= 0.0 x, y = GR.wctondc(0.05, r) - GR.text(x, y, string(signif(rmin + i * tick, 12))) + gr_text(x, y, _cycle(rtick_labels, i)) end end end From 6d14a858a389ab50cdeb6e5f73eaac5f1b652b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1ll=20Haraldsson?= Date: Tue, 7 Nov 2017 11:11:46 +0000 Subject: [PATCH 078/115] Typo? Guessing here, 0.2.0 must be really old? --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 05f416f6..966c3500 100644 --- a/NEWS.md +++ b/NEWS.md @@ -105,7 +105,7 @@ #### 0.11.0 - julia 0.6 compatibility -- matplotlib 0.2.0 compatibility +- matplotlib 2.0 compatibility - add inspectdr backend - improved histogram functionality: - added a `:stephist` and `:scatterhist` series type as well as ``:barhist` (the default) From 51d4630405a6db0081c174eb95930c6ff990e178 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 8 Nov 2017 22:02:40 +0100 Subject: [PATCH 079/115] change pgfplots legend symbol for shapes and filled plots --- src/backends/pgfplots.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index ef009fe1..93acf765 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -207,6 +207,9 @@ function pgf_series(sp::Subplot, series::Series) # add to legend? if sp[:legend] != :none && should_add_to_legend(series) kw[:legendentry] = d[:label] + if st == :shape || d[:fillrange] != nothing + push!(style, "area legend") + end else push!(style, "forget plot") end From 8bbdb0f1b8c784988a8b423c43291f6d44924d01 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sun, 12 Nov 2017 18:08:40 +0000 Subject: [PATCH 080/115] Adds radial data filtering for points within axis limits. --- src/backends/pgfplots.jl | 3 ++- src/backends/plotly.jl | 5 +++-- src/utils.jl | 23 +++++++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index da527f9a..43c15eab 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -221,7 +221,8 @@ function pgf_series(sp::Subplot, series::Series) # See "Scatter Plots" in PGFPlots documentation d[:x], d[:y], d[:marker_z] elseif ispolar(sp) - rad2deg.(d[:x]), d[:y] + theta, r = filter_radial_data(d[:x], d[:y], axis_limits(sp[:yaxis])) + rad2deg.(theta), r else d[:x], d[:y] end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9ada51f7..e9a662cc 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -717,8 +717,9 @@ end function plotly_polar!(d_out::KW, series::Series) # convert polar plots x/y to theta/radius if ispolar(series[:subplot]) - d_out[:t] = rad2deg.(pop!(d_out, :x)) - d_out[:r] = pop!(d_out, :y) + theta, r = filter_radial_data(pop!(d_out, :x), pop!(d_out, :y), axis_limits(series[:subplot][:yaxis])) + d_out[:t] = rad2deg.(theta) + d_out[:r] = r end end diff --git a/src/utils.jl b/src/utils.jl index 81cd3571..d19a2acb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -363,15 +363,26 @@ end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) rmin, rmax = r_extrema - phi, r = x, y + theta, r = filter_radial_data(x, y, r_extrema) r = (r - rmin) / (rmax - rmin) - n = max(length(phi), length(r)) - x = zeros(n) - y = zeros(n) + x = r.*cos.(theta) + y = r.*sin.(theta) + x, y +end + +# Filters radial data for points within the axis limits +function filter_radial_data(theta, r, r_extrema::Tuple{Real, Real}) + n = max(length(theta), length(r)) + rmin, rmax = r_extrema + x, y = zeros(n), zeros(n) for i in 1:n - x[i] = _cycle(r,i) * cos.(_cycle(phi,i)) - y[i] = _cycle(r,i) * sin.(_cycle(phi,i)) + x[i] = _cycle(theta, i) + y[i] = _cycle(r, i) end + points = map((a, b) -> (a, b), x, y) + filter!(a -> a[2] >= rmin && a[2] <= rmax, points) + x = map(a -> a[1], points) + y = map(a -> a[2], points) x, y end From 240c1efab9720148848896364cc6365df3695ae3 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Sun, 12 Nov 2017 18:09:08 +0000 Subject: [PATCH 081/115] Improve default radial axis padding. --- src/axes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 7ca04d2b..a3c3293c 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -437,7 +437,7 @@ function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis) amin, amax = 0, 2pi elseif lims == :auto #widen max radius so ticks dont overlap with theta axis - amin, 1.1*amax + amin, amax + 0.1 * abs(amax - amin) else amin, amax end From acf6e86c0fbb93e5c24d4f918a20dbcc6f8f4611 Mon Sep 17 00:00:00 2001 From: biggsbiggsby <33279473+biggsbiggsby@users.noreply.github.com> Date: Tue, 14 Nov 2017 09:39:59 +0100 Subject: [PATCH 082/115] gif animation.jl Change palette from png to gif to avoid png encoding bug in ffmpeg --- src/animation.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 8d3c0341..7faaa579 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -72,9 +72,9 @@ function buildanimation(animdir::AbstractString, fn::AbstractString, if is_animated_gif # generate a colorpalette first so ffmpeg does not have to guess it - run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.png`) + run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.gif`) # then apply the palette to get better results - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.png -lavfi paletteuse -y $fn`) + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.gif -lavfi paletteuse -y $fn`) else run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -pix_fmt yuv420p -y $fn`) end From 99f25ef744386d78cfa75b23b5f4f047ac7aa322 Mon Sep 17 00:00:00 2001 From: Andrew Palugniok Date: Tue, 14 Nov 2017 13:49:53 +0000 Subject: [PATCH 083/115] Fix typo. --- src/backends/pgfplots.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 43c15eab..7f4fbba3 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -310,7 +310,7 @@ function pgf_axis(sp::Subplot, letter) if !(axis[:ticks] in (nothing, false, :none)) && framestyle != :none ticks = get_ticks(axis) #pgf plot ignores ticks with angle below 90 when xmin = 90 so shift values - tick_values = ispolar(sp) && letter == :x ? [rad2deg.(ticks[1])[3:end]..., 360, 415] : ticks[1] + tick_values = ispolar(sp) && letter == :x ? [rad2deg.(ticks[1])[3:end]..., 360, 405] : ticks[1] push!(style, string(letter, "tick = {", join(tick_values,","), "}")) if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto # wrap the power part of label with } From ae37dce0f322f522ae4633eec8b7d381621d2a58 Mon Sep 17 00:00:00 2001 From: Huckleberry Febbo Date: Tue, 14 Nov 2017 13:43:17 -0500 Subject: [PATCH 084/115] allow legend to be outside for pgfplots() --- src/args.jl | 2 +- src/backends/pgfplots.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index afef5aeb..2bf63ac6 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1002,7 +1002,7 @@ function convertLegendValue(val::Symbol) :best elseif val in (:no, :none) :none - elseif val in (:right, :left, :top, :bottom, :inside, :best, :legend, :topright, :topleft, :bottomleft, :bottomright) + elseif val in (:right, :left, :top, :bottom, :inside, :best, :legend, :topright, :topleft, :bottomleft, :bottomright, :outertopright) val else error("Invalid symbol for legend: $val") diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index d455b638..d83917d0 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -94,6 +94,7 @@ const _pgfplots_legend_pos = KW( :bottomright => "south east", :topright => "north east", :topleft => "north west", + :outertopright => "outer north east", ) From cf58f3cbf238152d9a2b6b5199acb345588049dd Mon Sep 17 00:00:00 2001 From: biggsbiggsby <33279473+biggsbiggsby@users.noreply.github.com> Date: Fri, 17 Nov 2017 10:30:23 +0100 Subject: [PATCH 085/115] Update animation.jl Generates a color palette for each frame (instead of each animation) to improve quality, and avoid palette file format issues in FFMPEG 3.4 --- src/animation.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 7faaa579..760a56d2 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -71,10 +71,9 @@ function buildanimation(animdir::AbstractString, fn::AbstractString, fn = abspath(fn) if is_animated_gif - # generate a colorpalette first so ffmpeg does not have to guess it - run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf palettegen -y palette.gif`) - # then apply the palette to get better results - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i palette.gif -lavfi paletteuse -y $fn`) + # generate a colorpalette for each frame to improve quality + palette="palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1" + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -lavfi "$palette" -y $fn`) else run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -pix_fmt yuv420p -y $fn`) end From 1aa780f0a21218ba0ec34d6886e6ec0718efade9 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 17 Nov 2017 11:33:10 +0100 Subject: [PATCH 086/115] change legend symbols for shapes and filled plots on pyplot --- src/backends/pyplot.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d325b21b..a29b81b7 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -2,7 +2,7 @@ # https://github.com/stevengj/PyPlot.jl @require Revise begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "pyplot.jl")) end const _pyplot_attr = merge_with_base_supported([ @@ -1009,7 +1009,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) for lab in cb[:ax][:yaxis][:get_ticklabels]() lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) lab[:set_family](sp[:yaxis][:tickfont].family) - end + end sp.attr[:cbar_handle] = cb sp.attr[:cbar_ax] = cbax end @@ -1221,10 +1221,11 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) for series in series_list(sp) if should_add_to_legend(series) # add a line/marker and a label - push!(handles, if series[:seriestype] == :shape - PyPlot.plt[:Line2D]((0,1),(0,0), - color = py_color(_cycle(series[:fillcolor],1)), - linewidth = py_dpi_scale(plt, 4) + push!(handles, if series[:seriestype] == :shape || series[:fillrange] != nothing + pypatches[:Patch]( + edgecolor = py_color(_cycle(series[:linecolor],1)), + facecolor = py_color(_cycle(series[:fillcolor],1)), + linewidth = py_dpi_scale(plt, series[:linewidth]) ) elseif series[:seriestype] == :path PyPlot.plt[:Line2D]((0,1),(0,0), From ee0f4e11ea1d81bbb08c1763c35d858bc105daf1 Mon Sep 17 00:00:00 2001 From: biggsbiggsby <33279473+biggsbiggsby@users.noreply.github.com> Date: Fri, 17 Nov 2017 12:35:36 +0100 Subject: [PATCH 087/115] Update animation.jl Changed palette for each frame to an option, made the default palette a lossless bmp file for best quality/filesize, but still compatible with FFMPEG 3.4 on Win7 x64 --- src/animation.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/animation.jl b/src/animation.jl index 760a56d2..93f28427 100644 --- a/src/animation.jl +++ b/src/animation.jl @@ -67,13 +67,21 @@ mp4(anim::Animation, fn = mp4fn(); kw...) = buildanimation(anim.dir, fn, false; function buildanimation(animdir::AbstractString, fn::AbstractString, is_animated_gif::Bool=true; - fps::Integer = 20, loop::Integer = 0) + fps::Integer = 20, loop::Integer = 0, + variable_palette::Bool=false) fn = abspath(fn) if is_animated_gif - # generate a colorpalette for each frame to improve quality - palette="palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1" - run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -lavfi "$palette" -y $fn`) + if variable_palette + # generate a colorpalette for each frame for highest quality, but larger filesize + palette="palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1" + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -lavfi "$palette" -y $fn`) + else + # generate a colorpalette first so ffmpeg does not have to guess it + run(`ffmpeg -v 0 -i $(animdir)/%06d.png -vf "palettegen=stats_mode=diff" -y "$(animdir)/palette.bmp"`) + # then apply the palette to get better results + run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -i "$(animdir)/palette.bmp" -lavfi "paletteuse=dither=sierra2_4a" -y $fn`) + end else run(`ffmpeg -v 0 -framerate $fps -loop $loop -i $(animdir)/%06d.png -pix_fmt yuv420p -y $fn`) end From 4bc01b92bd3f980899429f75bc24f104da9a73f6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 17 Nov 2017 12:59:20 +0100 Subject: [PATCH 088/115] avoid too big linewidths in legend --- src/backends/pyplot.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index a29b81b7..fcac84c6 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1225,12 +1225,12 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) pypatches[:Patch]( edgecolor = py_color(_cycle(series[:linecolor],1)), facecolor = py_color(_cycle(series[:fillcolor],1)), - linewidth = py_dpi_scale(plt, series[:linewidth]) + linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)), ) elseif series[:seriestype] == :path - PyPlot.plt[:Line2D]((0,1),(0,0), + PyPlot.plt[:Line2D]((0, 1),(0,0), color = py_color(_cycle(series[:fillcolor],1)), - linewidth = py_dpi_scale(plt, 1), + linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)), marker = py_marker(series[:markershape]), markeredgecolor = py_markerstrokecolor(series), markerfacecolor = py_markercolor(series) From 4bfb56247714a5c656c3b7be1356a8515e8c9628 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 17 Nov 2017 13:01:13 +0100 Subject: [PATCH 089/115] remove extra space --- src/backends/pyplot.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index fcac84c6..1ef9a2d7 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1228,7 +1228,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)), ) elseif series[:seriestype] == :path - PyPlot.plt[:Line2D]((0, 1),(0,0), + PyPlot.plt[:Line2D]((0,1),(0,0), color = py_color(_cycle(series[:fillcolor],1)), linewidth = py_dpi_scale(plt, clamp(series[:linewidth], 0, 5)), marker = py_marker(series[:markershape]), From df023d6bdb42138029e4208db6c840957d775a2e Mon Sep 17 00:00:00 2001 From: Romain Franconville Date: Fri, 17 Nov 2017 15:02:16 -0500 Subject: [PATCH 090/115] Always define axis range explicitely --- src/backends/plotly.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 3b149a20..19c3ab14 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -252,7 +252,7 @@ function plotly_axis(axis::Axis, sp::Subplot) end ax[:tickangle] = -axis[:rotation] - + ax[:range] = axis_limits(axis) if !(axis[:ticks] in (nothing, :none)) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) @@ -288,6 +288,7 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:showgrid] = false end + ax end From c01d8199f9acd24f663769213b81d893c9e624b4 Mon Sep 17 00:00:00 2001 From: Romain Franconville Date: Fri, 17 Nov 2017 15:29:55 -0500 Subject: [PATCH 091/115] Also include scaling --- src/backends/plotly.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 19c3ab14..b7670449 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -252,7 +252,9 @@ function plotly_axis(axis::Axis, sp::Subplot) end ax[:tickangle] = -axis[:rotation] - ax[:range] = axis_limits(axis) + lims = axis_limits(axis) + ax[:range] = map(scalefunc(axis[:scale]), lims) + if !(axis[:ticks] in (nothing, :none)) ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) ax[:type] = plotly_scale(axis[:scale]) @@ -261,10 +263,10 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) # lims - lims = axis[:lims] - if lims != :auto && limsType(lims) == :limits - ax[:range] = map(scalefunc(axis[:scale]), lims) - end + + #if lims != :auto && limsType(lims) == :limits + #ax[:range] = map(scalefunc(axis[:scale]), lims) + #end # flip if axis[:flip] From 5a0744e2f137b2eec85e6616ad1fe454a5d733e6 Mon Sep 17 00:00:00 2001 From: Romain Franconville Date: Fri, 17 Nov 2017 16:06:14 -0500 Subject: [PATCH 092/115] Remove commented code --- src/backends/plotly.jl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index b7670449..b0906444 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -262,12 +262,6 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) - # lims - - #if lims != :auto && limsType(lims) == :limits - #ax[:range] = map(scalefunc(axis[:scale]), lims) - #end - # flip if axis[:flip] ax[:autorange] = "reversed" From ea976d5f08d9be7c0ff8db26b987d8727bcca5d5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 12:53:11 +0100 Subject: [PATCH 093/115] expand axes extrema for heatmap edges --- src/axes.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/axes.jl b/src/axes.jl index a3c3293c..d4fac7cb 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -380,6 +380,15 @@ function expand_extrema!(sp::Subplot, d::KW) expand_extrema!(axis, ignorenan_minimum(data) - 0.5minimum(bw)) end + # expand for heatmaps + if d[:seriestype] == :heatmap + for letter in (:x, :y) + data = d[letter] + axis = sp[Symbol(letter, "axis")] + scale = get(d, Symbol(letter, "scale"), :identity) + expand_extrema!(axis, heatmap_edges(data, scale)) + end + end end function expand_extrema!(sp::Subplot, xmin, xmax, ymin, ymax) From 9f5be974b60ad8dccb59dbc61d434a8368f91aa7 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 14:02:49 +0100 Subject: [PATCH 094/115] add fontfamily, fontsize, fonthalign, fontvalign, fontrotation, fontcolor keywords --- src/args.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/args.jl b/src/args.jl index 2bf63ac6..8c3159f9 100644 --- a/src/args.jl +++ b/src/args.jl @@ -273,6 +273,7 @@ const _plot_defaults = KW( :background_color => colorant"white", # default for all backgrounds, :background_color_outside => :match, # background outside grid, :foreground_color => :auto, # default for all foregrounds, and title color, + :fontfamily => "sans-serif", :size => (600,400), :pos => (0,0), :window_title => "Plots.jl", @@ -293,6 +294,12 @@ const _subplot_defaults = KW( :title => "", :title_location => :center, # also :left or :right :titlefont => font(14), + :titlefontfamily => :match, + :titlefontsize => 14, + :titlefonthalign => :hcenter, + :titlefontvalign => :vcenter, + :titlefontrotation => 0.0, + :titlefontcolor => :match, :background_color_subplot => :match, # default for other bg colors... match takes plot default :background_color_legend => :match, # background of legend :background_color_inside => :match, # background inside grid @@ -305,6 +312,12 @@ const _subplot_defaults = KW( :colorbar => :legend, :clims => :auto, :legendfont => font(8), + :legendfontfamily => :match, + :legendfontsize => 8, + :legendfonthalign => :hcenter, + :legendfontvalign => :vcenter, + :legendfontrotation => 0.0, + :legendfontcolor => :match, :annotations => [], # annotation tuples... list of (x,y,annotation) :projection => :none, # can also be :polar or :3d :aspect_ratio => :none, # choose from :none or :equal @@ -328,7 +341,19 @@ const _axis_defaults = KW( :flip => false, :link => [], :tickfont => font(8), + :tickfontfamily => :match, + :tickfontsize => 8, + :tickfonthalign => :hcenter, + :tickfontvalign => :vcenter, + :tickfontrotation => 0.0, + :tickfontcolor => :match, :guidefont => font(11), + :guidefontfamily => :match, + :guidefontsize => 11, + :guidefonthalign => :hcenter, + :guidefontvalign => :vcenter, + :guidefontrotation => 0.0, + :guidefontcolor => :match, :foreground_color_axis => :match, # axis border/tick colors, :foreground_color_border => :match, # plot area border/spines, :foreground_color_text => :match, # tick text color, @@ -1084,6 +1109,12 @@ const _match_map = KW( :top_margin => :margin, :right_margin => :margin, :bottom_margin => :margin, + :titlefontfamily => :fontfamily, + :labelfontfamily => :fontfamily, + :tickfontfamily => :fontfamily, + :guidefontfamily => :fontfamily, + :titlefontcolor => :foreground_color_subplot, + :labelfontcolor => :foreground_color_subplot, ) # these can match values from the parent container (axis --> subplot --> plot) @@ -1095,6 +1126,8 @@ const _match_map2 = KW( :foreground_color_grid => :foreground_color_subplot, :foreground_color_guide => :foreground_color_subplot, :foreground_color_text => :foreground_color_subplot, + :tickfontcolor => :foreground_color_text, + :guidefontcolor => :foreground_color_text, ) # properly retrieve from plt.attr, passing `:match` to the correct key From 68a060b7eb50121d62ce5578812e54719ae07eed Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 14:31:30 +0100 Subject: [PATCH 095/115] implement titlefont, legendfont, tickfont and guidefont magic keyword arguments --- src/args.jl | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/args.jl b/src/args.jl index 8c3159f9..b2c5958b 100644 --- a/src/args.jl +++ b/src/args.jl @@ -293,7 +293,6 @@ const _plot_defaults = KW( const _subplot_defaults = KW( :title => "", :title_location => :center, # also :left or :right - :titlefont => font(14), :titlefontfamily => :match, :titlefontsize => 14, :titlefonthalign => :hcenter, @@ -311,7 +310,6 @@ const _subplot_defaults = KW( :legendtitle => nothing, :colorbar => :legend, :clims => :auto, - :legendfont => font(8), :legendfontfamily => :match, :legendfontsize => 8, :legendfonthalign => :hcenter, @@ -340,14 +338,12 @@ const _axis_defaults = KW( :rotation => 0, :flip => false, :link => [], - :tickfont => font(8), :tickfontfamily => :match, :tickfontsize => 8, :tickfonthalign => :hcenter, :tickfontvalign => :vcenter, :tickfontrotation => 0.0, :tickfontcolor => :match, - :guidefont => font(11), :guidefontfamily => :match, :guidefontsize => 11, :guidefonthalign => :hcenter, @@ -768,6 +764,15 @@ function processGridArg!(d::KW, arg, letter) end end +processFontArgs!(d::KW, fontname::Symbol, args::Tuple) + fnt = font(args...) + d[Symbol(fontname, :family)] = fnt.family + d[Symbol(fontname, :size)] = fnt.pointsize + d[Symbol(fontname, :halign)] = fnt.halign + d[Symbol(fontname, :valign)] = fnt.valign + d[Symbol(fontname, :rotation)] = fnt.rotation + d[Symbol(fontname, :color)] = fnt.color +end _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape) _replace_markershape(shapes::AVec) = map(_replace_markershape, shapes) @@ -836,6 +841,25 @@ function preprocessArgs!(d::KW) end end + # fonts + for fontname in (:titlefont, :legendfont) + args = pop!(d, fontname, ()) + processFontArgs!(d, fontname, args) + end + # handle font args common to all axes + for fontname in (:tickfont, :guidefont) + args = pop!(d, fontname, ()) + for letter in (:x, :y, :z) + processFontArgs!(d, Symbol(letter, fontname), args) + end + end + # handle individual axes font args + for letter in (:x, :y, :z) + for fontname in (:tickfont, :guidefont) + args = pop!(d, Symbol(letter, fontname), ()) + processFontArgs!(d, Symbol(letter, fontname), args) + end + # handle line args for arg in wraptuple(pop!(d, :line, ())) processLineArg(d, arg) From 8fee5e0de7cdb91362ee7b9531c4830b59d0f262 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 14:58:30 +0100 Subject: [PATCH 096/115] implement titlefont legendfont tickfont and guidefont functions to construct font objects from subplots and axes --- src/args.jl | 2 +- src/utils.jl | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index b2c5958b..a5a63ad5 100644 --- a/src/args.jl +++ b/src/args.jl @@ -764,7 +764,7 @@ function processGridArg!(d::KW, arg, letter) end end -processFontArgs!(d::KW, fontname::Symbol, args::Tuple) +function processFontArgs!(d::KW, fontname::Symbol, args::Tuple) fnt = font(args...) d[Symbol(fontname, :family)] = fnt.family d[Symbol(fontname, :size)] = fnt.pointsize diff --git a/src/utils.jl b/src/utils.jl index d19a2acb..b9da48d5 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1007,3 +1007,43 @@ xmax(plt::Plot) = ignorenan_maximum([ignorenan_maximum(series.d[:x]) for series "Extrema of x-values in plot" ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt)) + + +# --------------------------------------------------------------- +# get fonts from objects: + +titlefont(sp::Subplot) = font( + sp[:titlefontfamily], + sp[:titlefontsize], + sp[:titlefont], + sp[:titlefonthalign], + sp[:titlefontrotation], + sp[:titlefontcolor], +) + +legendfont(sp::Subplot) = font( + sp[:legendfontfamily], + sp[:legendfontsize], + sp[:legendfont], + sp[:legendfonthalign], + sp[:legendfontrotation], + sp[:legendfontcolor], +) + +tickfont(ax::Axis) = font( + ax[:tickfontfamily], + ax[:tickfontsize], + ax[:tickfont], + ax[:tickfonthalign], + ax[:tickfontrotation], + ax[:tickfontcolor], +) + +guidefont(ax::Axis) = font( + ax[:guidefontfamily], + ax[:guidefontsize], + ax[:guidefont], + ax[:guidefonthalign], + ax[:guidefontrotation], + ax[:guidefontcolor], +) From ba3e75e710ce69a9dc5b0cc68f14febbfd074cfc Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 15:16:49 +0100 Subject: [PATCH 097/115] fix errors --- src/args.jl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/args.jl b/src/args.jl index a5a63ad5..84f8a4bc 100644 --- a/src/args.jl +++ b/src/args.jl @@ -418,10 +418,10 @@ const _all_defaults = KW[ const _initial_defaults = deepcopy(_all_defaults) # to be able to reset font sizes to initial values -const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefont].pointsize, - :legendfont => _subplot_defaults[:legendfont].pointsize, - :tickfont => _axis_defaults[:tickfont].pointsize, - :guidefont => _axis_defaults[:guidefont].pointsize) +const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefontsize], + :legendfont => _subplot_defaults[:legendfontsize], + :tickfont => _axis_defaults[:tickfontsize], + :guidefont => _axis_defaults[:guidefontsize]) const _all_args = sort(collect(union(map(keys, _all_defaults)...))) @@ -856,8 +856,9 @@ function preprocessArgs!(d::KW) # handle individual axes font args for letter in (:x, :y, :z) for fontname in (:tickfont, :guidefont) - args = pop!(d, Symbol(letter, fontname), ()) - processFontArgs!(d, Symbol(letter, fontname), args) + args = pop!(d, Symbol(letter, fontname), ()) + processFontArgs!(d, Symbol(letter, fontname), args) + end end # handle line args From 0da6f6b4a45b99944739ba5515c5fa6a0918a25e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 15:32:30 +0100 Subject: [PATCH 098/115] update gr --- src/backends/gr.jl | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9619f638..6c5e486b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -22,7 +22,14 @@ const _gr_attr = merge_with_base_supported([ :layout, :title, :window_title, :guide, :lims, :ticks, :scale, :flip, - :tickfont, :guidefont, :legendfont, + :titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign, + :titlefontrotation, :titlefontcolor, + :legendfontfamily, :legendfontsize, :legendfonthalign, :legendfontvalign, + :legendfontrotation, :legendfontcolor, + :tickfontfamily, :tickfontsize, :tickfonthalign, :tickfontvalign, + :tickfontrotation, :tickfontcolor, + :guidefontfamily, :guidefontsize, :guidefonthalign, :guidefontvalign, + :guidefontrotation, :guidefontcolor, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :legendtitle, :colorbar, :fill_z, :line_z, :marker_z, :levels, @@ -583,10 +590,9 @@ end function gr_set_xticks_font(sp) flip = sp[:yaxis][:flip] mirror = sp[:xaxis][:mirror] - gr_set_font(sp[:xaxis][:tickfont], + gr_set_font(tickfont(sp[:xaxis]), 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 @@ -595,10 +601,9 @@ end function gr_set_yticks_font(sp) flip = sp[:xaxis][:flip] mirror = sp[:yaxis][:mirror] - gr_set_font(sp[:yaxis][:tickfont], + gr_set_font(tickfont(sp[:yaxis]), 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 @@ -759,8 +764,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end # draw the axes - gr_set_font(xaxis[:tickfont]) - gr_set_textcolor(xaxis[:foreground_color_text]) + gr_set_font(tickfont(xaxis)) GR.setlinewidth(1) if is3d(sp) @@ -887,7 +891,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # add the guides GR.savestate() if sp[:title] != "" - gr_set_font(sp[:titlefont]) + gr_set_font(titlefont(sp)) loc = sp[:title_location] if loc == :left xpos = viewport_plotarea[1] @@ -905,22 +909,20 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end if xaxis[:guide] != "" - gr_set_font(xaxis[:guidefont]) + gr_set_font(guidefont(xaxis)) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_BOTTOM) - gr_set_textcolor(xaxis[:foreground_color_guide]) gr_text(gr_view_xcenter(), viewport_subplot[3], xaxis[:guide]) end if yaxis[:guide] != "" - gr_set_font(yaxis[:guidefont]) + gr_set_font(guidefont(yaxis)) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_TOP) GR.setcharup(-1, 0) - gr_set_textcolor(yaxis[:foreground_color_guide]) gr_text(viewport_subplot[1], gr_view_ycenter(), yaxis[:guide]) end GR.restorestate() - gr_set_font(xaxis[:tickfont]) + gr_set_font(tickfont(xaxis)) # this needs to be here to point the colormap to the right indices GR.setcolormap(1000 + GR.COLORMAP_COOLWARM) @@ -1193,7 +1195,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.savestate() GR.selntran(0) GR.setscale(0) - gr_set_font(sp[:legendfont]) + gr_set_font(legendfont(sp)) w = 0 i = 0 n = 0 @@ -1215,7 +1217,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) w = max(w, tbx[3] - tbx[1]) end if w > 0 - dy = _gr_point_mult[1] * sp[:legendfont].pointsize * 1.75 + dy = _gr_point_mult[1] * sp[:legendfontsize] * 1.75 h = dy*n (xpos,ypos) = gr_legend_pos(sp[:legend],w,h) GR.setfillintstyle(GR.INTSTYLE_SOLID) From 6e51a086943b3185bdd293a06d611ccfb81e0b3a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 15:36:11 +0100 Subject: [PATCH 099/115] fix errors --- src/args.jl | 2 +- src/utils.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/args.jl b/src/args.jl index 84f8a4bc..f9621d76 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1152,7 +1152,7 @@ const _match_map2 = KW( :foreground_color_guide => :foreground_color_subplot, :foreground_color_text => :foreground_color_subplot, :tickfontcolor => :foreground_color_text, - :guidefontcolor => :foreground_color_text, + :guidefontcolor => :foreground_color_guide, ) # properly retrieve from plt.attr, passing `:match` to the correct key diff --git a/src/utils.jl b/src/utils.jl index b9da48d5..c5a4baa0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1015,7 +1015,7 @@ ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt)) titlefont(sp::Subplot) = font( sp[:titlefontfamily], sp[:titlefontsize], - sp[:titlefont], + sp[:titlefontvalign], sp[:titlefonthalign], sp[:titlefontrotation], sp[:titlefontcolor], @@ -1024,7 +1024,7 @@ titlefont(sp::Subplot) = font( legendfont(sp::Subplot) = font( sp[:legendfontfamily], sp[:legendfontsize], - sp[:legendfont], + sp[:legendfontvalign], sp[:legendfonthalign], sp[:legendfontrotation], sp[:legendfontcolor], @@ -1033,7 +1033,7 @@ legendfont(sp::Subplot) = font( tickfont(ax::Axis) = font( ax[:tickfontfamily], ax[:tickfontsize], - ax[:tickfont], + ax[:tickfontvalign], ax[:tickfonthalign], ax[:tickfontrotation], ax[:tickfontcolor], @@ -1042,7 +1042,7 @@ tickfont(ax::Axis) = font( guidefont(ax::Axis) = font( ax[:guidefontfamily], ax[:guidefontsize], - ax[:guidefont], + ax[:guidefontvalign], ax[:guidefonthalign], ax[:guidefontrotation], ax[:guidefontcolor], From e80a73cc1c7c90a56734b752c89cd195f3e6df7a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 16:59:54 +0100 Subject: [PATCH 100/115] fix magic font argument and cascading font defaults --- src/args.jl | 69 +++++++++++++++++++++++++++++++++------------- src/backends/gr.jl | 5 ++-- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/args.jl b/src/args.jl index f9621d76..df11cabf 100644 --- a/src/args.jl +++ b/src/args.jl @@ -293,6 +293,7 @@ const _plot_defaults = KW( const _subplot_defaults = KW( :title => "", :title_location => :center, # also :left or :right + :fontfamily_subplot => :match, :titlefontfamily => :match, :titlefontsize => 14, :titlefonthalign => :hcenter, @@ -764,14 +765,37 @@ function processGridArg!(d::KW, arg, letter) end end -function processFontArgs!(d::KW, fontname::Symbol, args::Tuple) - fnt = font(args...) - d[Symbol(fontname, :family)] = fnt.family - d[Symbol(fontname, :size)] = fnt.pointsize - d[Symbol(fontname, :halign)] = fnt.halign - d[Symbol(fontname, :valign)] = fnt.valign - d[Symbol(fontname, :rotation)] = fnt.rotation - d[Symbol(fontname, :color)] = fnt.color +function processFontArg!(d::KW, fontname::Symbol, arg) + T = typeof(arg) + if T <: Font + d[Symbol(fontname, :family)] = arg.family + d[Symbol(fontname, :size)] = arg.pointsize + d[Symbol(fontname, :halign)] = arg.halign + d[Symbol(fontname, :valign)] = arg.valign + d[Symbol(fontname, :rotation)] = arg.rotation + d[Symbol(fontname, :color)] = arg.color + elseif arg == :center + d[Symbol(fontname, :halign)] = :hcenter + d[Symbol(fontname, :valign)] = :vcenter + elseif arg in (:hcenter, :left, :right) + d[Symbol(fontname, :halign)] = arg + elseif arg in (:vcenter, :top, :bottom) + d[Symbol(fontname, :valign)] = arg + elseif T <: Colorant + d[Symbol(fontname, :color)] = arg + elseif T <: Symbol || T <: AbstractString + try + d[Symbol(fontname, :color)] = parse(Colorant, string(arg)) + catch + d[Symbol(fontname, :family)] = string(arg) + end + elseif typeof(arg) <: Integer + d[Symbol(fontname, :size)] = arg + elseif typeof(arg) <: Real + d[Symbol(fontname, :rotation)] = convert(Float64, arg) + else + warn("Skipped font arg: $arg ($(typeof(arg)))") + end end _replace_markershape(shape::Symbol) = get(_markerAliases, shape, shape) @@ -844,20 +868,26 @@ function preprocessArgs!(d::KW) # fonts for fontname in (:titlefont, :legendfont) args = pop!(d, fontname, ()) - processFontArgs!(d, fontname, args) + for arg in wraptuple(args) + processFontArg!(d, fontname, arg) + end end # handle font args common to all axes for fontname in (:tickfont, :guidefont) args = pop!(d, fontname, ()) - for letter in (:x, :y, :z) - processFontArgs!(d, Symbol(letter, fontname), args) + for arg in wraptuple(args) + for letter in (:x, :y, :z) + processFontArg!(d, Symbol(letter, fontname), arg) + end end end # handle individual axes font args for letter in (:x, :y, :z) for fontname in (:tickfont, :guidefont) args = pop!(d, Symbol(letter, fontname), ()) - processFontArgs!(d, Symbol(letter, fontname), args) + for arg in wraptuple(args) + processFontArg!(d, Symbol(letter, fontname), arg) + end end end @@ -1134,12 +1164,12 @@ const _match_map = KW( :top_margin => :margin, :right_margin => :margin, :bottom_margin => :margin, - :titlefontfamily => :fontfamily, - :labelfontfamily => :fontfamily, - :tickfontfamily => :fontfamily, - :guidefontfamily => :fontfamily, + :titlefontfamily => :fontfamily_subplot, + :legendfontfamily => :fontfamily_subplot, :titlefontcolor => :foreground_color_subplot, - :labelfontcolor => :foreground_color_subplot, + :legendfontcolor => :foreground_color_subplot, + :tickfontcolor => :foreground_color_text, + :guidefontcolor => :foreground_color_guide, ) # these can match values from the parent container (axis --> subplot --> plot) @@ -1151,8 +1181,9 @@ const _match_map2 = KW( :foreground_color_grid => :foreground_color_subplot, :foreground_color_guide => :foreground_color_subplot, :foreground_color_text => :foreground_color_subplot, - :tickfontcolor => :foreground_color_text, - :guidefontcolor => :foreground_color_guide, + :fontfamily_subplot => :fontfamily, + :tickfontfamily => :fontfamily_subplot, + :guidefontfamily => :fontfamily_subplot, ) # properly retrieve from plt.attr, passing `:match` to the correct key diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 6c5e486b..7261ca2c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -904,7 +904,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) halign = GR.TEXT_HALIGN_CENTER end GR.settextalign(halign, GR.TEXT_VALIGN_TOP) - gr_set_textcolor(sp[:foreground_color_title]) gr_text(xpos, viewport_subplot[4], sp[:title]) end @@ -1229,7 +1228,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) i = 0 if sp[:legendtitle] != nothing GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF) - gr_set_textcolor(sp[:foreground_color_legend]) + gr_set_textcolor(sp[:legendfontcolor]) GR.settransparency(1) gr_text(xpos - 0.03 + 0.5*w, ypos, string(sp[:legendtitle])) ypos -= dy @@ -1271,7 +1270,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) lab = series[:label] end GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) - gr_set_textcolor(sp[:foreground_color_legend]) + gr_set_textcolor(sp[:legendfontcolor]) gr_text(xpos, ypos, lab) ypos -= dy end From 60d20ea998d341080b9be78e91173297690b73ff Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 18:15:22 +0100 Subject: [PATCH 101/115] update pyplot --- src/args.jl | 12 ++++++------ src/backends/pyplot.jl | 36 +++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/args.jl b/src/args.jl index df11cabf..70fa458c 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1164,12 +1164,12 @@ const _match_map = KW( :top_margin => :margin, :right_margin => :margin, :bottom_margin => :margin, - :titlefontfamily => :fontfamily_subplot, - :legendfontfamily => :fontfamily_subplot, - :titlefontcolor => :foreground_color_subplot, - :legendfontcolor => :foreground_color_subplot, - :tickfontcolor => :foreground_color_text, - :guidefontcolor => :foreground_color_guide, + :titlefontfamily => :fontfamily_subplot, + :legendfontfamily => :fontfamily_subplot, + :titlefontcolor => :foreground_color_subplot, + :legendfontcolor => :foreground_color_subplot, + :tickfontcolor => :foreground_color_text, + :guidefontcolor => :foreground_color_guide, ) # these can match values from the parent container (axis --> subplot --> plot) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 1ef9a2d7..d6c9c778 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -19,7 +19,10 @@ const _pyplot_attr = merge_with_base_supported([ :title, :title_location, :titlefont, :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, - :tickfont, :guidefont, :legendfont, + :titlefontfamily, :titlefontsize, :titlefontcolor, + :legendfontfamily, :legendfontsize, :legendfontcolor, + :tickfontfamily, :tickfontsize, :tickfontcolor, + :guidefontfamily, :guidefontsize, :guidefontcolor, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :legendtitle, :colorbar, :marker_z, :line_z, :fill_z, @@ -128,6 +131,7 @@ end # # anything else just gets a bluesred gradient # py_colormap(c, α=nothing) = py_colormap(default_gradient(), α) +py_color(s) = py_color(parse(Colorant, string(s))) py_color(c::Colorant) = (red(c), green(c), blue(c), alpha(c)) py_color(cs::AVec) = map(py_color, cs) py_color(grad::ColorGradient) = py_color(grad.colors) @@ -923,8 +927,8 @@ function py_set_axis_colors(sp, ax, a::Axis) tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis]) ax[:tick_params](axis=string(a[:letter]), which="both", colors=tickcolor, - labelcolor=py_color(a[:foreground_color_text])) - ax[axissym][:label][:set_color](py_color(a[:foreground_color_guide])) + labelcolor=py_color(a[:tickfontcolor])) + ax[axissym][:label][:set_color](py_color(a[:guidefontcolor])) end end @@ -978,9 +982,9 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) :title end ax[func][:set_text](sp[:title]) - ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefont].pointsize)) - ax[func][:set_family](sp[:titlefont].family) - ax[func][:set_color](py_color(sp[:foreground_color_title])) + ax[func][:set_fontsize](py_dpi_scale(plt, sp[:titlefontsize])) + ax[func][:set_family](sp[:titlefontfamily]) + ax[func][:set_color](py_color(sp[:titlefontcolor])) # ax[:set_title](sp[:title], loc = loc) end @@ -1005,10 +1009,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) fig = plt.o cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) cb = fig[:colorbar](handle; cax = cbax, kw...) - cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefont].pointsize),family=sp[:yaxis][:guidefont].family) + cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontamily], color = py_color(sp[:yaxis][:guidefontcolor])) for lab in cb[:ax][:yaxis][:get_ticklabels]() - lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfont].pointsize)) - lab[:set_family](sp[:yaxis][:tickfont].family) + lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfontsize])) + lab[:set_family](sp[:yaxis][:tickfontfamily]) + lab[:set_color](py_color(sp[:yaxis][:tickfontcolor])) end sp.attr[:cbar_handle] = cb sp.attr[:cbar_ax] = cbax @@ -1068,11 +1073,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) if get(axis.d, :flip, false) ax[Symbol("invert_", letter, "axis")]() end - pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefont].pointsize)) - pyaxis[:label][:set_family](axis[:guidefont].family) + pyaxis[:label][:set_fontsize](py_dpi_scale(plt, axis[:guidefontsize])) + pyaxis[:label][:set_family](axis[:guidefontfamily]) for lab in ax[Symbol("get_", letter, "ticklabels")]() - lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfont].pointsize)) - lab[:set_family](axis[:tickfont].family) + lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfontsize])) + lab[:set_family](axis[:tickfontfamily]) lab[:set_rotation](axis[:rotation]) end if axis[:grid] && !(ticks in (:none, nothing, false)) @@ -1248,7 +1253,7 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) labels, loc = get(_pyplot_legend_pos, leg, "best"), scatterpoints = 1, - fontsize = py_dpi_scale(plt, sp[:legendfont].pointsize) + fontsize = py_dpi_scale(plt, sp[:legendfontsize]) # family = sp[:legendfont].family # framealpha = 0.6 ) @@ -1256,8 +1261,9 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) sp[:legendtitle] != nothing && leg[:set_title](sp[:legendtitle]) fgcolor = py_color(sp[:foreground_color_legend]) + lfcolor = py_color(sp[:legendfontcolor]) for txt in leg[:get_texts]() - PyPlot.plt[:setp](txt, color = fgcolor, family = sp[:legendfont].family) + PyPlot.plt[:setp](txt, color = lfcolor, family = sp[:legendfontfamily]) end # set some legend properties From 7ec54b9c2e41b555aec6bbe8c41778711b331a46 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 19:54:52 +0100 Subject: [PATCH 102/115] update plotly(js) --- src/backends.jl | 6 +++--- src/backends/plotly.jl | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/backends.jl b/src/backends.jl index 1dd5d8ad..94199b00 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -51,8 +51,8 @@ _series_updated(plt::Plot, series::Series) = nothing _before_layout_calcs(plt::Plot) = nothing -title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefont].pointsize * pt -guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefont].pointsize * pt +title_padding(sp::Subplot) = sp[:title] == "" ? 0mm : sp[:titlefontsize] * pt +guide_padding(axis::Axis) = axis[:guide] == "" ? 0mm : axis[:guidefontsize] * pt "Returns the (width,height) of a text label." function text_size(lablen::Int, sz::Number, rot::Number = 0) @@ -93,7 +93,7 @@ function tick_padding(axis::Axis) # hgt # get the height of the rotated label - text_size(longest_label, axis[:tickfont].pointsize, rot)[2] + text_size(longest_label, axis[:tickfontsize], rot)[2] end end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 3b149a20..e58d685c 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -2,7 +2,7 @@ # https://plot.ly/javascript/getting-started @require Revise begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) end const _plotly_attr = merge_with_base_supported([ @@ -19,7 +19,12 @@ const _plotly_attr = merge_with_base_supported([ :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :markerstrokestyle, :fillrange, :fillcolor, :fillalpha, :bins, - :title, :title_location, :titlefont, + :title, :title_location, + :titlefontfamily, :titlefontsize, :titlefonthalign, :titlefontvalign, + :titlefontcolor, + :legendfontfamily, :legendfontsize, :legendfontcolor, + :tickfontfamily, :tickfontsize, :tickfontcolor, + :guidefontfamily, :guidefontsize, :guidefontcolor, :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, :tickfont, :guidefont, :legendfont, @@ -254,9 +259,9 @@ function plotly_axis(axis::Axis, sp::Subplot) ax[:tickangle] = -axis[:rotation] if !(axis[:ticks] in (nothing, :none)) - ax[:titlefont] = plotly_font(axis[:guidefont], axis[:foreground_color_guide]) + ax[:titlefont] = plotly_font(guidefont(axis)) ax[:type] = plotly_scale(axis[:scale]) - ax[:tickfont] = plotly_font(axis[:tickfont], axis[:foreground_color_text]) + ax[:tickfont] = plotly_font(tickfont(axis)) ax[:tickcolor] = framestyle in (:zerolines, :grid) || !axis[:showaxis] ? rgba_string(invisible()) : rgb_string(axis[:foreground_color_axis]) ax[:linecolor] = rgba_string(axis[:foreground_color_axis]) @@ -334,8 +339,8 @@ function plotly_layout(plt::Plot) 0.5 * (left(bb) + right(bb)) end titlex, titley = xy_mm_to_pcts(xmm, top(bbox(sp)), w*px, h*px) - titlefont = font(sp[:titlefont], :top, sp[:foreground_color_title]) - push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], titlefont))) + title_font = font(titlefont(sp), :top) + push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], title_font))) end d_out[:plot_bgcolor] = rgba_string(sp[:background_color_inside]) @@ -376,7 +381,7 @@ function plotly_layout(plt::Plot) d_out[:legend] = KW( :bgcolor => rgba_string(sp[:background_color_legend]), :bordercolor => rgba_string(sp[:foreground_color_legend]), - :font => plotly_font(sp[:legendfont], sp[:foreground_color_legend]), + :font => plotly_font(legendfont(sp)), :x => xpos, :y => ypos ) From d4f67ec3b573ea70e67efae657b58c95434d6f52 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 20:31:28 +0100 Subject: [PATCH 103/115] update glvisualize --- src/backends/glvisualize.jl | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 924eca72..b0d93511 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -10,7 +10,7 @@ TODO =# @require Revise begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "glvisualize.jl")) end const _glvisualize_attr = merge_with_base_supported([ @@ -24,10 +24,10 @@ const _glvisualize_attr = merge_with_base_supported([ :markerstrokewidth, :markerstrokecolor, :markerstrokealpha, :fillrange, :fillcolor, :fillalpha, :bins, :bar_width, :bar_edges, :bar_position, - :title, :title_location, :titlefont, + :title, :title_location, :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, - :tickfont, :guidefont, :legendfont, + :tickfont, :guidefont, :legendfont, :titlefont, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :colorbar, :marker_z, @@ -612,7 +612,7 @@ function draw_ticks( axis, ticks, isx, isorigin, lims, m, text = "", positions = Point2f0[], offsets=Vec2f0[] ) - sz = pointsize(axis[:tickfont]) + sz = pointsize(tickfont(axis)) atlas = GLVisualize.get_texture_atlas() font = GLVisualize.defaultfont() @@ -745,7 +745,7 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are :position => map(x-> x[2], ticklabels), :offset => map(last, ticklabels), :color => fcolor, - :relative_scale => pointsize(xaxis[:tickfont]), + :relative_scale => pointsize(tickfont(xaxis)), :scale_primitive => false ) push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) @@ -760,7 +760,7 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are :position => map(x-> x[2], ticklabels), :offset => map(last, ticklabels), :color => fcolor, - :relative_scale => pointsize(xaxis[:tickfont]), + :relative_scale => pointsize(tickfont(xaxis)), :scale_primitive => false ) push!(axis_vis, visualize(map(first, ticklabels), Style(:default), kw_args)) @@ -777,8 +777,8 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are area_w = GeometryTypes.widths(area) if sp[:title] != "" - tf = sp[:titlefont]; color = gl_color(sp[:foreground_color_title]) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, color) + tf = titlefont(sp) + font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, tf.rotation, tf.color) xy = Point2f0(area.w/2, area_w[2] + pointsize(tf)/2) kw = Dict(:model => text_model(font, xy), :scale_primitive => true) extract_font(font, kw) @@ -786,9 +786,9 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are push!(axis_vis, glvisualize_text(xy, t, kw)) end if xaxis[:guide] != "" - tf = xaxis[:guidefont]; color = gl_color(xaxis[:foreground_color_guide]) + tf = guidefont(xaxis) xy = Point2f0(area.w/2, - pointsize(tf)/2) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, color) + font = Plots.Font(tf.family, tf.pointsize, :hcenter, :bottom, tf.rotation, tf.color) kw = Dict(:model => text_model(font, xy), :scale_primitive => true) t = PlotText(xaxis[:guide], font) extract_font(font, kw) @@ -796,8 +796,8 @@ function gl_draw_axes_2d(sp::Plots.Subplot{Plots.GLVisualizeBackend}, model, are end if yaxis[:guide] != "" - tf = yaxis[:guidefont]; color = gl_color(yaxis[:foreground_color_guide]) - font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, color) + tf = guidefont(yaxis) + font = Plots.Font(tf.family, tf.pointsize, :hcenter, :top, 90f0, tf.color) xy = Point2f0(-pointsize(tf)/2, area.h/2) kw = Dict(:model => text_model(font, xy), :scale_primitive=>true) t = PlotText(yaxis[:guide], font) @@ -1483,9 +1483,8 @@ function make_label(sp, series, i) else series[:label] end - color = sp[:foreground_color_legend] - ft = sp[:legendfont] - font = Plots.Font(ft.family, ft.pointsize, :left, :bottom, 0.0, color) + ft = legendfont(sp) + font = Plots.Font(ft.family, ft.pointsize, :left, :bottom, 0.0, ft.color) xy = Point2f0(w+gap, 0.0) kw = Dict(:model => text_model(font, xy), :scale_primitive=>false) extract_font(font, kw) From 189b2e5cd61a926ca347604bda1d67355456a743 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 20:36:26 +0100 Subject: [PATCH 104/115] update glvisualize --- src/backends/glvisualize.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index b0d93511..f89b8afc 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -27,7 +27,10 @@ const _glvisualize_attr = merge_with_base_supported([ :title, :title_location, :window_title, :guide, :lims, :ticks, :scale, :flip, :rotation, - :tickfont, :guidefont, :legendfont, :titlefont, + :titlefontsize, :titlefontcolor, + :legendfontsize, :legendfontcolor, + :tickfontsize, + :guidefontsize, :guidefontcolor, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :colorbar, :marker_z, From 78f10de8cda80d06ffdadd9a7dbf671f657e2bc5 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 20:44:22 +0100 Subject: [PATCH 105/115] update inspectdr --- src/backends/inspectdr.jl | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 7d09045a..3718b2ee 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -14,7 +14,7 @@ Add in functionality to Plots.jl: =# @require Revise begin - Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) + Revise.track(Plots, joinpath(Pkg.dir("Plots"), "src", "backends", "inspectdr.jl")) end # --------------------------------------------------------------------------- @@ -32,10 +32,13 @@ const _inspectdr_attr = merge_with_base_supported([ :markerstrokestyle, #Causes warning not to have it... what is this? :fillcolor, :fillalpha, #:fillrange, # :bins, :bar_width, :bar_edges, :bar_position, - :title, :title_location, :titlefont, + :title, :title_location, :window_title, :guide, :lims, :scale, #:ticks, :flip, :rotation, - :tickfont, :guidefont, :legendfont, + :titlefontfamily, :titlefontsize, :titlefontcolor, + :legendfontfamily, :legendfontsize, :legendfontcolor, + :tickfontfamily, :tickfontsize, :tickfontcolor, + :guidefontfamily, :guidefontsize, :guidefontcolor, :grid, :legend, #:colorbar, # :marker_z, # :line_z, @@ -373,24 +376,24 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) l[:frame_canvas].fillcolor = _inspectdr_mapcolor(sp[:background_color_subplot]) l[:frame_data].fillcolor = _inspectdr_mapcolor(sp[:background_color_inside]) l[:frame_data].line.color = _inspectdr_mapcolor(xaxis[:foreground_color_axis]) - l[:font_title] = InspectDR.Font(sp[:titlefont].family, - _inspectdr_mapptsize(sp[:titlefont].pointsize), - color = _inspectdr_mapcolor(sp[:foreground_color_title]) + l[:font_title] = InspectDR.Font(sp[:titlefontfamily], + _inspectdr_mapptsize(sp[:titlefontsize]), + color = _inspectdr_mapcolor(sp[:titlefontcolor]) ) #Cannot independently control fonts of axes with InspectDR: - l[:font_axislabel] = InspectDR.Font(xaxis[:guidefont].family, - _inspectdr_mapptsize(xaxis[:guidefont].pointsize), - color = _inspectdr_mapcolor(xaxis[:foreground_color_guide]) + l[:font_axislabel] = InspectDR.Font(xaxis[:guidefontfamily], + _inspectdr_mapptsize(xaxis[:guidefontsize]), + color = _inspectdr_mapcolor(xaxis[:guidefontcolor]) ) - l[:font_ticklabel] = InspectDR.Font(xaxis[:tickfont].family, - _inspectdr_mapptsize(xaxis[:tickfont].pointsize), - color = _inspectdr_mapcolor(xaxis[:foreground_color_text]) + l[:font_ticklabel] = InspectDR.Font(xaxis[:tickfontfamily], + _inspectdr_mapptsize(xaxis[:tickfontsize]), + color = _inspectdr_mapcolor(xaxis[:tickfontcolor]) ) l[:enable_legend] = (sp[:legend] != :none) #l[:halloc_legend] = 150 #TODO: compute??? - l[:font_legend] = InspectDR.Font(sp[:legendfont].family, - _inspectdr_mapptsize(sp[:legendfont].pointsize), - color = _inspectdr_mapcolor(sp[:foreground_color_legend]) + l[:font_legend] = InspectDR.Font(sp[:legendfontfamily], + _inspectdr_mapptsize(sp[:legendfontsize]), + color = _inspectdr_mapcolor(sp[:legendfontcolor]) ) l[:frame_legend].fillcolor = _inspectdr_mapcolor(sp[:background_color_legend]) end From 129a91b36fcc2e3cef70b8e8bf7a726481838f17 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 19 Nov 2017 21:18:04 +0100 Subject: [PATCH 106/115] update arg description --- src/arg_desc.jl | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index f0df3e92..386639b6 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -66,11 +66,17 @@ const _arg_desc = KW( :dpi => "Number. Dots Per Inch of output figures", :display_type => "Symbol (`:auto`, `:gui`, or `:inline`). When supported, `display` will either open a GUI window or plot inline.", :extra_kwargs => "KW (Dict{Symbol,Any}). Pass a map of extra keyword args which may be specific to a backend.", +:fontfamily => "String or Symbol. Default font family for title, legend entries, tick labels and guides", # subplot args :title => "String. Subplot title.", :title_location => "Symbol. Position of subplot title. Values: `:left`, `:center`, `:right`", -:titlefont => "Font. Font of subplot title.", +:titlefontfamily => "String or Symbol. Font family of subplot title.", +:titlefontsize => "Integer. Font pointsize of subplot title.", +:titlefonthalign => "Symbol. Font horizontal alignment of subplot title: :hcenter, :left, :right or :center", +:titlefontvalign => "Symbol. Font vertical alignment of subplot title: :vcenter, :top, :bottom or :center", +:titlefontrotation => "Real. Font rotation of subplot title", +:titlefontcolor => "Color Type. Font color of subplot title", :background_color_subplot => "Color Type or `:match` (matches `:background_color`). Base background color of the subplot.", :background_color_legend => "Color Type or `:match` (matches `:background_color_subplot`). Background color of the legend.", :background_color_inside => "Color Type or `:match` (matches `:background_color_subplot`). Background color inside the plot area (under the grid).", @@ -79,7 +85,12 @@ const _arg_desc = KW( :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)", -:legendtitle => "String or nothing (default). Sets the legend title.", +:legendfontfamily => "String or Symbol. Font family of legend entries.", +:legendfontsize => "Integer. Font pointsize of legend entries.", +:legendfonthalign => "Symbol. Font horizontal alignment of legend entries: :hcenter, :left, :right or :center", +:legendfontvalign => "Symbol. Font vertical alignment of legend entries: :vcenter, :top, :bottom or :center", +:legendfontrotation => "Real. Font rotation of legend entries", +:legendfontcolor => "Color Type. Font color of legend entries", :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.", @@ -104,8 +115,18 @@ const _arg_desc = KW( :rotation => "Number. Degrees rotation of tick labels.", :flip => "Bool. Should we flip (reverse) the axis?", :formatter => "Function, :scientific, or :auto. A method which converts a number to a string for tick labeling.", -:tickfont => "Font. Font of axis tick labels.", -:guidefont => "Font. Font of axis guide (label).", +:tickfontfamily => "String or Symbol. Font family of tick labels.", +:tickfontsize => "Integer. Font pointsize of tick labels.", +:tickfonthalign => "Symbol. Font horizontal alignment of tick labels: :hcenter, :left, :right or :center", +:tickfontvalign => "Symbol. Font vertical alignment of tick labels: :vcenter, :top, :bottom or :center", +:tickfontrotation => "Real. Font rotation of tick labels", +:tickfontcolor => "Color Type. Font color of tick labels", +:guidefontfamily => "String or Symbol. Font family of axes guides.", +:guidefontsize => "Integer. Font pointsize of axes guides.", +:guidefonthalign => "Symbol. Font horizontal alignment of axes guides: :hcenter, :left, :right or :center", +:guidefontvalign => "Symbol. Font vertical alignment of axes guides: :vcenter, :top, :bottom or :center", +:guidefontrotation => "Real. Font rotation of axes guides", +:guidefontcolor => "Color Type. Font color of axes guides", :foreground_color_axis => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of axis ticks.", :foreground_color_border => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of plot area border (spines).", :foreground_color_text => "Color Type or `:match` (matches `:foreground_color_subplot`). Color of tick labels.", From f7765c80b84d96c8de1ce68a7888f9de311e85e6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 20 Nov 2017 16:54:05 +0100 Subject: [PATCH 107/115] fix guidefontamily typo in pyplot --- src/backends/pyplot.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d6c9c778..81bc5a94 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1009,7 +1009,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) fig = plt.o cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym())) cb = fig[:colorbar](handle; cax = cbax, kw...) - cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontamily], color = py_color(sp[:yaxis][:guidefontcolor])) + cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, sp[:yaxis][:guidefontsize]),family=sp[:yaxis][:guidefontfamily], color = py_color(sp[:yaxis][:guidefontcolor])) for lab in cb[:ax][:yaxis][:get_ticklabels]() lab[:set_fontsize](py_dpi_scale(plt, sp[:yaxis][:tickfontsize])) lab[:set_family](sp[:yaxis][:tickfontfamily]) From dbf96a69d78f47a9f38b63ec8c29c141cbea003f Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Tue, 21 Nov 2017 13:58:03 +0100 Subject: [PATCH 108/115] gr: fix 'hidden window' problem after savefig --- src/backends/gr.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 7261ca2c..2a10ad02 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1329,12 +1329,18 @@ for (mime, fmt) in _gr_mimeformats @eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GRBackend}) GR.emergencyclosegks() filepath = tempname() * "." * $fmt + env = get(ENV, "GKSwstype", "0") ENV["GKSwstype"] = $fmt ENV["GKS_FILEPATH"] = filepath gr_display(plt) GR.emergencyclosegks() write(io, readstring(filepath)) rm(filepath) + if env != "0" + ENV["GKSwstype"] = env + else + pop!(ENV,"GKSwstype") + end end end From 6d4717fc96f59af7ebebf2a5c208ee1c188b3ce4 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 22 Nov 2017 21:26:53 +0100 Subject: [PATCH 109/115] gr: added support for non-string legend labels --- src/backends/gr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 2a10ad02..912ad1d1 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1212,7 +1212,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) else lab = series[:label] end - tbx, tby = gr_inqtext(0, 0, lab) + tbx, tby = gr_inqtext(0, 0, string(lab)) w = max(w, tbx[3] - tbx[1]) end if w > 0 @@ -1271,7 +1271,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF) gr_set_textcolor(sp[:legendfontcolor]) - gr_text(xpos, ypos, lab) + gr_text(xpos, ypos, string(lab)) ypos -= dy end end From 714f8dea1dcce2c4c02ee4052f27cf56e295e337 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 30 Nov 2017 09:45:09 +0100 Subject: [PATCH 110/115] fix axes limits for fill=true in 3d plots --- src/axes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index d4fac7cb..a31e7228 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -355,7 +355,7 @@ function expand_extrema!(sp::Subplot, d::KW) if fr == nothing && d[:seriestype] == :bar fr = 0.0 end - if fr != nothing + if fr != nothing && !all3D(d) axis = sp.attr[vert ? :yaxis : :xaxis] if typeof(fr) <: Tuple for fri in fr From 4c55ff5df846b402eebdec7f4514d47611f7fc49 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 30 Nov 2017 11:01:12 +0100 Subject: [PATCH 111/115] use new StatPlots df syntax in testexamples --- src/examples.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples.jl b/src/examples.jl index b3ac5f6b..ac9a3d62 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -252,7 +252,7 @@ PlotExample("DataFrames", [:(begin import RDatasets iris = RDatasets.dataset("datasets", "iris") - scatter(iris, :SepalLength, :SepalWidth, group=:Species, + @df iris scatter(:SepalLength, :SepalWidth, group=:Species, title = "My awesome plot", xlabel = "Length", ylabel = "Width", marker = (0.5, [:cross :hex :star7], 12), bg=RGB(.2,.2,.2)) end)] From 49eb2c426d11d24d1a37822f9d2f1a3a6d105f72 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 30 Nov 2017 11:05:05 +0100 Subject: [PATCH 112/115] update testexample 30 --- src/examples.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/examples.jl b/src/examples.jl index ac9a3d62..481db2a9 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -301,8 +301,8 @@ PlotExample("Boxplot and Violin series recipes", [:(begin import RDatasets singers = RDatasets.dataset("lattice", "singer") - violin(singers, :VoicePart, :Height, line = 0, fill = (0.2, :blue)) - boxplot!(singers, :VoicePart, :Height, line = (2,:black), fill = (0.3, :orange)) + @df singers violin(:VoicePart, :Height, line = 0, fill = (0.2, :blue)) + @df singers boxplot!(:VoicePart, :Height, line = (2,:black), fill = (0.3, :orange)) end)] ), From dd16c7d560ad5127bda2a726bbd92f1afa762eab Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 30 Nov 2017 11:47:20 +0100 Subject: [PATCH 113/115] extend grid lines to axes limits --- src/axes.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index d4fac7cb..ccb3611d 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -577,7 +577,7 @@ function axis_drawing_info(sp::Subplot) push!(xtick_segs, (xtick, tick_start), (xtick, tick_stop)) # bottom tick end # sp[:draw_axes_border] && push!(xaxis_segs, (xtick, ymax), (xtick, t2)) # top tick - xaxis[:grid] && push!(xgrid_segs, (xtick, t1), (xtick, t2)) # vertical grid + xaxis[:grid] && push!(xgrid_segs, (xtick, ymin), (xtick, ymax)) # vertical grid end end @@ -616,7 +616,7 @@ function axis_drawing_info(sp::Subplot) push!(ytick_segs, (tick_start, ytick), (tick_stop, ytick)) # left tick end # sp[:draw_axes_border] && push!(yaxis_segs, (xmax, ytick), (t2, ytick)) # right tick - yaxis[:grid] && push!(ygrid_segs, (t1, ytick), (t2, ytick)) # horizontal grid + yaxis[:grid] && push!(ygrid_segs, (xmin, ytick), (xmax, ytick)) # horizontal grid end end end From a7fcf77251af7100edd027d7b02106652471f847 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 30 Nov 2017 16:26:48 +0100 Subject: [PATCH 114/115] allow to change the foreground_color_legend in gr --- src/backends/gr.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 912ad1d1..1530d19e 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1222,8 +1222,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.setfillintstyle(GR.INTSTYLE_SOLID) gr_set_fillcolor(sp[:background_color_legend]) GR.fillrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n) - GR.setlinetype(1) - GR.setlinewidth(1) + gr_set_line(1, :solid, sp[:foreground_color_legend]) GR.drawrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n) i = 0 if sp[:legendtitle] != nothing From 28c958fb2032523181c8396a9afc3f4d1d689d6a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 1 Dec 2017 16:14:59 +0100 Subject: [PATCH 115/115] set tick marks color to grid color for framestyle = :grid --- src/backends/pyplot.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 81bc5a94..8a9c7680 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -924,7 +924,7 @@ function py_set_axis_colors(sp, ax, a::Axis) end axissym = Symbol(a[:letter], :axis) if haskey(ax, axissym) - tickcolor = sp[:framestyle] == :zerolines ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis]) + tickcolor = sp[:framestyle] in (:zerolines, :grid) ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis]) ax[:tick_params](axis=string(a[:letter]), which="both", colors=tickcolor, labelcolor=py_color(a[:tickfontcolor]))