From a045c40889044249ea6acdb1a9c778a1879dca92 Mon Sep 17 00:00:00 2001 From: "Nicholas R. Jankowski" Date: Wed, 16 Oct 2024 13:29:10 -0400 Subject: [PATCH] bar/barh - Fix tick mark labels after changing x/y data (bug #65734). * __bar__.m (update_axes_limits): Add isrow check to force column vector orientation on xdata before procesing tick and label changes. * bar.m, barh.m: Add BISTs to verify correct axes limits, and tick marks, and labels. * NEWS.9.md: Note change under 9.3.0 Improvements and fixes. --- etc/NEWS.9.md | 4 +- scripts/plot/draw/bar.m | 61 +++++++++++++++++++++++++++++ scripts/plot/draw/barh.m | 60 ++++++++++++++++++++++++++++ scripts/plot/draw/private/__bar__.m | 8 ++++ 4 files changed, 132 insertions(+), 1 deletion(-) diff --git a/etc/NEWS.9.md b/etc/NEWS.9.md index 87b51206f7..f85ad898d3 100644 --- a/etc/NEWS.9.md +++ b/etc/NEWS.9.md @@ -27,7 +27,9 @@ Summary of bugs fixed for version 9.3.0 (tbd): patch and surface graphics objects (bug #66314). - `barh` properties now better match equivalent `bar` plot. Changing `horizontal` property for a bar or barh plot now consistently updates - properties to match redrawn plot (bug #65671). + properties to match redrawn plot (bug #65671). +- Tick mark labels are now correctly updated after changing x or y data for + `bar` and `barh` plots (bug #65734). ### GUI diff --git a/scripts/plot/draw/bar.m b/scripts/plot/draw/bar.m index 6e8dde11a6..1caa9d468f 100644 --- a/scripts/plot/draw/bar.m +++ b/scripts/plot/draw/bar.m @@ -863,6 +863,67 @@ %! close (hf); %! end_unwind_protect +## Ensure x tick labels are updated with xdata changes. +%!test <*65734> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hb = bar (hax, 2:4); +%! hp = get (hb, "children"); +%! +%! assert (get (hb, "xdata"), [1:3]'); +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! +%! set (hb, "xdata", [3:5]'); # column vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[2.5, 5.5], 3:5, {"3"; "4"; "5"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! +%! set (hb, "xdata", [9:11]); # row vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[8.5, 11.5], 9:11, {"9"; "10"; "11"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +#### Ensure y tick labels are updated with ydata changes. +%!test <*65734> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hb = bar (hax, 2:4); +%! hp = get (hb, "children"); +%! +%! assert (get (hb, "xdata"), [1:3]'); +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! +%! set (hb, "ydata", [5:7]'); # column vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0, 7], [0:7], {"0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"}}); +%! +%! set (hb, "ydata", [-4:-2]); # row vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[-4, 0], [-4:0], {"-4"; "-3"; "-2"; "-1"; "0"}}); +%! +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + + %% Test input validation %!error bar () %!error bar ("foo") diff --git a/scripts/plot/draw/barh.m b/scripts/plot/draw/barh.m index d828e6f430..e1cdd2294b 100644 --- a/scripts/plot/draw/barh.m +++ b/scripts/plot/draw/barh.m @@ -842,6 +842,66 @@ %! close (hf); %! end_unwind_protect +## Ensure x tick labels are updated with xdata changes. +%!test <*65734> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hb = barh (hax, 2:4); +%! hp = get (hb, "children"); +%! +%! assert (get (hb, "xdata"), [1:3]'); +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! +%! set (hb, "xdata", [3:5]'); # column vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[2.5, 5.5], 3:5, {"3"; "4"; "5"}}); +%! +%! set (hb, "xdata", [9:11]); # row vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[8.5, 11.5], 9:11, {"9"; "10"; "11"}}); +%! +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +#### Ensure y tick labels are updated with ydata changes. +%!test <*65734> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hb = barh (hax, 2:4); +%! hp = get (hb, "children"); +%! +%! assert (get (hb, "xdata"), [1:3]'); +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0, 4], [0:4], {"0"; "1"; "2"; "3"; "4"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! +%! set (hb, "ydata", [5:7]'); # column vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[0, 7], [0:7], {"0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}});%! +%! +%! set (hb, "ydata", [-4:-2]); # row vector input. +%! assert (get (hax, {"xlim", "xtick","xticklabel"}), ... +%! {[-4, 0], [-4:0], {"-4"; "-3"; "-2"; "-1"; "0"}}); +%! assert (get (hax, {"ylim", "ytick", "yticklabel"}), ... +%! {[0.5, 3.5], 1:3, {"1"; "2"; "3"}}); +%! +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + %% Test input validation %!error bar () diff --git a/scripts/plot/draw/private/__bar__.m b/scripts/plot/draw/private/__bar__.m index a60fa0c947..addf93d974 100644 --- a/scripts/plot/draw/private/__bar__.m +++ b/scripts/plot/draw/private/__bar__.m @@ -623,6 +623,14 @@ function update_axes_limits (hax, x, vertical, ishistc) ## a small number of integers. ## Then temporarily set to auto to reset limits around patch elements and ## baseline component parallel to bars. + + ## Vector x inputs to bar are forced to be column vectors. x inputs from + ## set command may be forced to row vectors. Ensure column vector for + ## bar tick processing. See bug #65734. + if (isrow (x)) + x = x(:); + endif + if (vertical) set (hax, "xtick", x(:,1)); set (hax, "xlimmode", "auto");