add tick_direction=:none option to hide tick labels

This commit is contained in:
Daniel Schwabeneder 2021-04-28 20:27:50 +02:00
parent fd50469e20
commit 7bb2132b18
6 changed files with 59 additions and 35 deletions

View File

@ -165,7 +165,7 @@ const _arg_desc = KW(
:minorgridalpha => "Number in [0,1]. The alpha/opacity override for the minorgrid lines.",
:minorgridstyle => "Symbol. Style of the minor grid lines. Choose from $(_allStyles)",
:minorgridlinewidth => "Number. Width of the minor grid lines (in pixels)",
:tick_direction => "Symbol. Direction of the ticks. `:in` or `:out`",
:tick_direction => "Symbol. Direction of the ticks. `:in`, `:out` or `:none`",
:showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`",
:widen => "Bool. Widen the axis limits by a small factor to avoid cut-off markers and lines at the borders. Defaults to `true`.",
:draw_arrow => "Bool. Draw arrow at the end of the axis.",

View File

@ -697,17 +697,19 @@ function axis_drawing_info(sp, letter)
if !(ax[:ticks] in (:none, nothing, false))
f = RecipesPipeline.scale_func(oax[:scale])
invf = RecipesPipeline.inverse_scale_func(oax[:scale])
tick_start, tick_stop = if sp[:framestyle] == :origin
t = invf(f(0) + 0.012 * (f(oamax) - f(oamin)))
(-t, t)
else
ticks_in = ax[:tick_direction] == :out ? -1 : 1
t = invf(f(oa1) + 0.012 * (f(oa2) - f(oa1)) * ticks_in)
(oa1, t)
if ax[:tick_direction] !== :none
tick_start, tick_stop = if sp[:framestyle] == :origin
t = invf(f(0) + 0.012 * (f(oamax) - f(oamin)))
(-t, t)
else
ticks_in = ax[:tick_direction] == :out ? -1 : 1
t = invf(f(oa1) + 0.012 * (f(oa2) - f(oa1)) * ticks_in)
(oa1, t)
end
end
for tick in ticks[1]
if ax[:showaxis]
if ax[:showaxis] && ax[:tick_direction] !== :none
push!(
tick_segments,
reverse_if((tick, tick_start), isy),
@ -834,18 +836,20 @@ function axis_drawing_info_3d(sp, letter)
if !(ax[:ticks] in (:none, nothing, false))
f = RecipesPipeline.scale_func(nax[:scale])
invf = RecipesPipeline.inverse_scale_func(nax[:scale])
tick_start, tick_stop = if sp[:framestyle] == :origin
t = invf(f(0) + 0.012 * (f(namax) - f(namin)))
(-t, t)
else
ticks_in = ax[:tick_direction] == :out ? -1 : 1
t = invf(f(na0) + 0.012 * (f(na1) - f(na0)) * ticks_in)
(na0, t)
if ax[:tick_direction] !== :none
tick_start, tick_stop = if sp[:framestyle] == :origin
t = invf(f(0) + 0.012 * (f(namax) - f(namin)))
(-t, t)
else
ticks_in = ax[:tick_direction] == :out ? -1 : 1
t = invf(f(na0) + 0.012 * (f(na1) - f(na0)) * ticks_in)
(na0, t)
end
end
ga0, ga1 = sp[:framestyle] in (:origin, :zerolines) ? (namin, namax) : (na0, na1)
for tick in ticks[1]
if ax[:showaxis]
if ax[:showaxis] && ax[:tick_direction] !== :none
push!(
tick_segments,
sort_3d_axes(tick, tick_start, fa0, letter),
@ -875,7 +879,7 @@ function axis_drawing_info_3d(sp, letter)
(na0, t)
end
for tick in minor_ticks
if ax[:showaxis]
if ax[:showaxis] && ax[:tick_direction] !== :none
push!(
tick_segments,
sort_3d_axes(tick, tick_start, fa0, letter),

View File

@ -1278,11 +1278,18 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
else
push!(opt, string(letter, "ticklabels") => "{}")
end
push!(
opt,
string(letter, "tick align") =>
(axis[:tick_direction] == :out ? "outside" : "inside"),
)
if axis[:tick_direction] === :none
push!(
opt,
string(letter, "tick style") => "draw=none",
)
else
push!(
opt,
string(letter, "tick align") =>
(axis[:tick_direction] == :out ? "outside" : "inside"),
)
end
push!(
opt, string(letter, "ticklabel style") => pgfx_get_ticklabel_style(sp, axis)
)

View File

@ -143,7 +143,8 @@ function plotly_axis(axis, sp, anchor = nothing, domain = nothing)
:zerolinecolor => rgba_string(axis[:foreground_color_axis]),
:showline => framestyle in (:box, :axes) && axis[:showaxis],
:linecolor => rgba_string(plot_color(axis[:foreground_color_axis])),
:ticks => axis[:tick_direction] == :out ? "outside" : "inside",
:ticks => axis[:tick_direction] === :out ? "outside" :
axis[:tick_direction] === :in ? "inside" : "",
:mirror => framestyle == :box,
:showticklabels => axis[:showaxis],
)

View File

@ -1022,7 +1022,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
cbar_axis."set_tick_params"(
direction = axis[:tick_direction] == :out ? "out" : "in",
width=py_thickness_scale(plt, intensity),
length= 5 * py_thickness_scale(plt, intensity)
length = axis[:tick_direction] == :none ? 0 : 5 * py_thickness_scale(plt, intensity)
)
@ -1137,7 +1137,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
pyaxis."set_tick_params"(
direction = axis[:tick_direction] == :out ? "out" : "in",
width=py_thickness_scale(plt, intensity),
length= 5 * py_thickness_scale(plt, intensity)
length = axis[:tick_direction] == :none ? 0 : 5 * py_thickness_scale(plt, intensity)
)
getproperty(ax, Symbol("set_", letter, "label"))(axis[:guide])
@ -1176,7 +1176,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
pyaxis."set_tick_params"(
which = "minor",
direction = axis[:tick_direction] == :out ? "out" : "in",
width=py_thickness_scale(plt, intensity))
length = axis[:tick_direction] == :none ? 0 : py_thickness_scale(plt, intensity),
)
end
if axis[:minorgrid]
@ -1186,7 +1187,8 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
pyaxis."set_tick_params"(
which = "minor",
direction = axis[:tick_direction] == :out ? "out" : "in",
width=py_thickness_scale(plt, intensity))
length = axis[:tick_direction] == :none ? 0 : py_thickness_scale(plt, intensity)
)
pyaxis."grid"(true,
which = "minor",

View File

@ -472,13 +472,23 @@ end
fillto = map(x -> _is_positive(x) ? typeof(baseline)(x) : baseline, fillto)
end
if !isnothing(plotattributes[:series_annotations])
if isvertical(plotattributes)
annotations := (x,y,plotattributes[:series_annotations].strs,:bottom)
else
annotations := (y,x,plotattributes[:series_annotations].strs,:left)
annotations = pop_kw!(plotattributes, :series_annotations, nothing)
isvert = isvertical(plotattributes)
if !isnothing(annotations)
@series begin
primary := false
seriestype := :scatter
markersize := 0
series_annotations := annotations
orientation := default(:orientation)
isvert ? (x, y) : (y, x)
end
series_annotations := nothing
# if isvertical(plotattributes)
# annotations := (x,y,plotattributes[:series_annotations].strs,:bottom)
# else
# annotations := (y,x,plotattributes[:series_annotations].strs,:left)
# end
# series_annotations := nothing
end
# create the bar shapes by adding x/y segments
@ -505,7 +515,7 @@ end
expand_extrema!(axis, widen(ignorenan_extrema(xseg.pts)...))
# switch back
if !isvertical(plotattributes)
if !isvert
xseg, yseg = yseg, xseg
end