From fa7f10a6e905b7acf7a05a9d412c7483fa7b1275 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 9 Apr 2020 17:56:54 +0200 Subject: [PATCH 1/2] implement minorgrid for pgfplotsx --- src/backends/pgfplotsx.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 0b3281e9..7874b2fc 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1028,6 +1028,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) push!(opt, string(letter, :min) => lims[1], string(letter, :max) => lims[2]) if !(axis[:ticks] in (nothing, false, :none, :native)) && framestyle != :none + # ticks ticks = get_ticks(sp, axis) #pgf plot ignores ticks with angle below 90 when xmin = 90 so shift values tick_values = @@ -1093,6 +1094,35 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) axis[:gridstyle], ), ) + + # minor ticks + # NOTE: PGFPlots would provide "minor x ticks num", but this only places minor ticks + # between major ticks and not outside first and last tick to the axis limits. + # Hence, we hack around with extra ticks. + minor_ticks = get_minor_ticks(sp, axis, ticks) + if minor_ticks !== nothing + minor_ticks = + ispolar(sp) && letter == :x ? [rad2deg.(minor_ticks)[3:end]..., 360, 405] : + minor_ticks + push!( + opt, + string("extra ", letter, " ticks") => string("{", join(minor_ticks, ","), "}"), + ) + push!(opt, string("extra ", letter, " tick labels") => "") + push!( + opt, + string("extra ", letter, " tick style") => PGFPlotsX.Options( + "grid" => axis[:minorgrid] ? "major" : "none", + string(letter, " grid style") => pgfx_linestyle( + pgfx_thickness_scaling(sp) * axis[:minorgridlinewidth], + axis[:foreground_color_minor_grid], + axis[:minorgridalpha], + axis[:minorgridstyle], + ), + "major tick length" => axis[:minorticks] ? "0.1cm" : "0" + ), + ) + end end # framestyle From 9bf4bda852fc62bfb9bc3bc0b027e30c167b2b8d Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 9 Apr 2020 18:13:28 +0200 Subject: [PATCH 2/2] fix zerolines framestyle and don't draw tick marks for zerolines and grid framestyle --- src/backends/pgfplotsx.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 7874b2fc..3d54cf65 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -1013,6 +1013,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) # ticks on or off if axis[:ticks] in (nothing, false, :none) || framestyle == :none push!(opt, "$(letter)majorticks" => "false") + elseif framestyle in (:grid, :zerolines) + push!(opt, "$letter tick style" => PGFPlotsX.Options("draw" => "none")) end # grid on or off @@ -1098,7 +1100,9 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) # minor ticks # NOTE: PGFPlots would provide "minor x ticks num", but this only places minor ticks # between major ticks and not outside first and last tick to the axis limits. - # Hence, we hack around with extra ticks. + # Hence, we hack around with extra ticks. Unfortunately this conflicts with + # `:zerolines` framestyle hack. So minor ticks are not working with + # `:zerolines`. minor_ticks = get_minor_ticks(sp, axis, ticks) if minor_ticks !== nothing minor_ticks = @@ -1144,7 +1148,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) opt, string("extra ", letter, " tick style") => PGFPlotsX.Options( "grid" => "major", - "major grid style" => pgfx_linestyle( + string(letter, " grid style") => pgfx_linestyle( pgfx_thickness_scaling(sp), axis[:foreground_color_border], 1.0,