From b73ea55bbde6bfc5bd4f21e102b04051e423f4fb Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 27 Sep 2017 13:53:06 +0200 Subject: [PATCH 1/5] implement tick_direction for GR, PyPlot, Plotly and GLVisualize --- src/arg_desc.jl | 1 + src/args.jl | 3 ++- src/axes.jl | 18 ++++++++++-------- src/backends/gr.jl | 4 ++-- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 1 + 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 8634eabb..88bc8cf8 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -115,4 +115,5 @@ 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`" ) diff --git a/src/args.jl b/src/args.jl index 0e9f4569..2ceeaa93 100644 --- a/src/args.jl +++ b/src/args.jl @@ -322,6 +322,7 @@ const _axis_defaults = KW( :gridalpha => 0.1, :gridstyle => :solid, :gridlinewidth => 0.5, + :tick_direction => :in, ) const _suppress_warnings = Set{Symbol}([ @@ -511,7 +512,7 @@ add_aliases(:stride, :wirefame_stride, :surface_stride, :surf_str, :str) add_aliases(:gridlinewidth, :gridwidth, :grid_linewidth, :grid_width, :gridlw, :grid_lw) add_aliases(:gridstyle, :grid_style, :gridlinestyle, :grid_linestyle, :grid_ls, :gridls) add_aliases(:framestyle, :frame_style, :frame, :axesstyle, :axes_style, :boxstyle, :box_style, :box, :borderstyle, :border_style, :border) - +add_aliases(:tick_direction, :tickdirection, :tick_dir, :tickdir, :tick_orientation, :tickorientation, :tick_or, :tickor) # add all pluralized forms to the _keyAliases dict for arg in keys(_series_defaults) diff --git a/src/axes.jl b/src/axes.jl index 61370a27..7e628f10 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -530,13 +530,14 @@ function axis_drawing_info(sp::Subplot) if !(xaxis[:ticks] in (nothing, false)) f = scalefunc(yaxis[:scale]) invf = invscalefunc(yaxis[:scale]) - t1 = invf(f(ymin) + 0.015*(f(ymax)-f(ymin))) - t2 = invf(f(ymax) - 0.015*(f(ymax)-f(ymin))) - t3 = invf(f(0) - 0.015*(f(ymax)-f(ymin))) + ticks_in = xaxis[:tick_direction] == :out ? -1 : 1 + t1 = invf(f(ymin) + 0.013 * (f(ymax) - f(ymin)) * ticks_in) + t2 = invf(f(ymax) - 0.013 * (f(ymax) - f(ymin)) * ticks_in) + t3 = invf(f(0) + 0.013 * (f(ymax) - f(ymin)) * ticks_in) for xtick in xticks[1] tick_start, tick_stop = if sp[:framestyle] == :origin - (0, xaxis[:mirror] ? -t3 : t3) + (0, t3) else xaxis[:mirror] ? (ymax, t2) : (ymin, t1) end @@ -560,13 +561,14 @@ function axis_drawing_info(sp::Subplot) if !(yaxis[:ticks] in (nothing, false)) f = scalefunc(xaxis[:scale]) invf = invscalefunc(xaxis[:scale]) - t1 = invf(f(xmin) + 0.015*(f(xmax)-f(xmin))) - t2 = invf(f(xmax) - 0.015*(f(xmax)-f(xmin))) - t3 = invf(f(0) - 0.015*(f(xmax)-f(xmin))) + ticks_in = yaxis[:tick_direction] == :out ? -1 : 1 + t1 = invf(f(xmin) + 0.013 * (f(xmax) - f(xmin)) * ticks_in) + t2 = invf(f(xmax) - 0.013 * (f(xmax) - f(xmin)) * ticks_in) + t3 = invf(f(0) + 0.013 * (f(xmax) - f(xmin)) * ticks_in) for ytick in yticks[1] tick_start, tick_stop = if sp[:framestyle] == :origin - (0, yaxis[:mirror] ? -t3 : t3) + (0, t3) else yaxis[:mirror] ? (xmax, t2) : (xmin, t1) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 09fb7270..b1680c20 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -827,7 +827,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # use xor ($) to get the right y coords xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin) # @show cv dv ymin xi yi flip mirror (flip $ mirror) - gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3, string(dv)) + gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0), string(dv)) end end @@ -838,7 +838,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # use xor ($) to get the right y coords xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv) # @show cv dv xmin xi yi - gr_text(xi + (mirror ? 1 : -1) * 1e-2, yi, string(dv)) + gr_text(xi + (mirror ? 1 : -1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0), yi, string(dv)) end end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 6753787e..02236e04 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -235,7 +235,7 @@ function plotly_axis(axis::Axis, sp::Subplot) :zerolinecolor => rgba_string(axis[:foreground_color_axis]), :showline => framestyle in (:box, :axes), :linecolor => rgba_string(plot_color(axis[:foreground_color_axis])), - :ticks => "inside", + :ticks => axis[:tick_direction] == :out ? "outside" : "inside", :mirror => framestyle == :box, ) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index d9f36015..27f28e18 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1052,6 +1052,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) ticks[2][ticks[1] .== 0] = "" end py_set_ticks(ax, ticks, letter) + pyaxis[:set_tick_params](direction = axis[:tick_direction] == :out ? "out" : "in") ax[Symbol("set_", letter, "label")](axis[:guide]) if get(axis.d, :flip, false) ax[Symbol("invert_", letter, "axis")]() From 350237a7740fddb100ca7ab7cef0c27a8d32bc0f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 27 Sep 2017 13:56:12 +0200 Subject: [PATCH 2/5] add tick_direction to supported arguments --- src/backends/glvisualize.jl | 1 + src/backends/gr.jl | 1 + src/backends/plotly.jl | 1 + src/backends/pyplot.jl | 1 + 4 files changed, 4 insertions(+) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index f9c01f29..1bdb79df 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -41,6 +41,7 @@ const _glvisualize_attr = merge_with_base_supported([ :dpi, :hover, :framestyle, + :tick_direction, ]) const _glvisualize_seriestype = [ :path, :shape, diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b1680c20..fcd93547 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -33,6 +33,7 @@ const _gr_attr = merge_with_base_supported([ :bar_width, :arrow, :framestyle, + :tick_direction, ]) const _gr_seriestype = [ :path, :scatter, diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 02236e04..1dd9060a 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -34,6 +34,7 @@ const _plotly_attr = merge_with_base_supported([ :bar_width, :clims, :framestyle, + :tick_direction, ]) const _plotly_seriestype = [ diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 27f28e18..ea0ba6c7 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -34,6 +34,7 @@ const _pyplot_attr = merge_with_base_supported([ :colorbar_title, :stride, :framestyle, + :tick_direction, ]) const _pyplot_seriestype = [ :path, :steppre, :steppost, :shape, From 69fa9e7b1034c47a0978cb85b92a0deb519300d6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 27 Sep 2017 17:07:09 +0200 Subject: [PATCH 3/5] implement tick_direction for PGFPlots --- src/backends/pgfplots.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backends/pgfplots.jl b/src/backends/pgfplots.jl index 30169147..046a4def 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -31,6 +31,7 @@ const _pgfplots_attr = merge_with_base_supported([ # :normalize, :weights, :contours, :aspect_ratio, # :match_dimensions, + :tick_direction, ]) const _pgfplots_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape] const _pgfplots_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot] @@ -283,6 +284,7 @@ function pgf_axis(sp::Subplot, letter) ticks = get_ticks(axis) push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) + push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) end # return the style list and KW args From 6c84624d713bfdc0d939508f49ac71fdf76984d9 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 27 Sep 2017 23:22:55 +0200 Subject: [PATCH 4/5] fix pgfplots --- 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 046a4def..97d68421 100644 --- a/src/backends/pgfplots.jl +++ b/src/backends/pgfplots.jl @@ -280,7 +280,7 @@ function pgf_axis(sp::Subplot, letter) kw[Symbol(letter,:max)] = lims[2] end - if !(axis[:ticks] in (nothing, false, :none, :auto)) + if !(axis[:ticks] in (nothing, false, :none)) ticks = get_ticks(axis) push!(style, string(letter, "tick = {", join(ticks[1],","), "}")) push!(style, string(letter, "ticklabels = {", join(ticks[2],","), "}")) From 1c048238777efe6ccbb623be329fa631451b1048 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 28 Sep 2017 00:07:58 +0200 Subject: [PATCH 5/5] reset tick size for gr and glvisualize --- src/axes.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 7e628f10..f989a8fb 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -531,9 +531,9 @@ function axis_drawing_info(sp::Subplot) f = scalefunc(yaxis[:scale]) invf = invscalefunc(yaxis[:scale]) ticks_in = xaxis[:tick_direction] == :out ? -1 : 1 - t1 = invf(f(ymin) + 0.013 * (f(ymax) - f(ymin)) * ticks_in) - t2 = invf(f(ymax) - 0.013 * (f(ymax) - f(ymin)) * ticks_in) - t3 = invf(f(0) + 0.013 * (f(ymax) - f(ymin)) * ticks_in) + t1 = invf(f(ymin) + 0.015 * (f(ymax) - f(ymin)) * ticks_in) + t2 = invf(f(ymax) - 0.015 * (f(ymax) - f(ymin)) * ticks_in) + 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 @@ -562,9 +562,9 @@ function axis_drawing_info(sp::Subplot) f = scalefunc(xaxis[:scale]) invf = invscalefunc(xaxis[:scale]) ticks_in = yaxis[:tick_direction] == :out ? -1 : 1 - t1 = invf(f(xmin) + 0.013 * (f(xmax) - f(xmin)) * ticks_in) - t2 = invf(f(xmax) - 0.013 * (f(xmax) - f(xmin)) * ticks_in) - t3 = invf(f(0) + 0.013 * (f(xmax) - f(xmin)) * ticks_in) + t1 = invf(f(xmin) + 0.015 * (f(xmax) - f(xmin)) * ticks_in) + t2 = invf(f(xmax) - 0.015 * (f(xmax) - f(xmin)) * ticks_in) + 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