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..f989a8fb 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.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 - (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.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 - (0, yaxis[:mirror] ? -t3 : t3) + (0, t3) else yaxis[:mirror] ? (xmax, t2) : (xmin, t1) end 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 09fb7270..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, @@ -827,7 +828,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 +839,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/pgfplots.jl b/src/backends/pgfplots.jl index 30169147..97d68421 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] @@ -279,10 +280,11 @@ 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],","), "}")) + push!(style, string(letter, "tick align = ", (axis[:tick_direction] == :out ? "outside" : "inside"))) end # return the style list and KW args diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 6753787e..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 = [ @@ -235,7 +236,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..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, @@ -1052,6 +1053,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")]()