From 18188516ec7c02994b57ae7e7ffff03c56edd189 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 29 Sep 2017 11:48:17 +0200 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 e3b0f7cd94c89bfc75a7c1dfff993eb92c1a1ece Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 4 Oct 2017 13:40:56 +0200 Subject: [PATCH 7/7] 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