Skip to content

Commit 7af365c

Browse files
authored
fix: don't ignore rticks() when the r-axis is not visible
For polar plots the (unsightly, and unhelpful) r-axis is hidden by default, instead of the grid being enabled by default. This PR handles rticks(), rtickformat(), rticklabels() and rtickangle() to generate the corresponding gnuplot commands even when the r-axis is hidden. Additionally, it handles `rticks({})` and `rticklabels({})` properly by essentially setting `rtickformat("")`. This ensures that labels are hidden without having to disable the grid.
1 parent e32cabd commit 7af365c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

source/matplot/core/axes_type.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,15 @@ namespace matplot {
429429
std::string axis_name,
430430
bool minor_ticks = false) {
431431
// cb is the only axis we don't unset if tics are empty
432-
if (ax.visible() && !ax.tick_values().empty()) {
432+
// r-axis labels should still be handled even if axis is invisible since we use the grid
433+
if ((ax.visible() || axis_name == "r") && !ax.tick_values().empty()) {
434+
if (axis_name == "r" && !ax.visible()) {
435+
// Hide the r-axis but not the grid.
436+
// We can't completely unset the tics or the grid does not
437+
// appear properly
438+
run_command("unset " + axis_name + "axis");
439+
run_command("set " + axis_name + "tics scale 0");
440+
}
433441
if (ax.geographic()) {
434442
run_command("set " + axis_name + "tics geographic");
435443
}
@@ -461,13 +469,21 @@ namespace matplot {
461469
run_command("set m" + axis_name + "tics 2");
462470
}
463471
}
464-
} else {
472+
} else { // (!visible && !r) || empty
465473
if (axis_name == "r") {
466474
// Hiding the r-axis works differently.
467475
// We can't completely unset the tics or the grid does not
468476
// appear properly
469477
run_command("unset " + axis_name + "axis");
470478
run_command("set " + axis_name + "tics scale 0");
479+
if (ax.tick_values().empty()) {
480+
// Note: Disabling tick labels without also
481+
// disabling the grid works via 'set format'
482+
// as per gnuplot manual "xticks" (see tic
483+
// labels). using 'set xticks () ...' would be
484+
// insufficient.
485+
run_command("set format " + axis_name + " \"\"");
486+
}
471487
} else if (axis_name == "cb") {
472488
// the colorbar / colorbox has a special command to unset it
473489
// if only ticks are empty we still want to show the box

0 commit comments

Comments
 (0)