From 51cb731ab5d6168d442a29c21beec7ab070642b2 Mon Sep 17 00:00:00 2001 From: Lucas Gruwez Date: Sun, 14 Sep 2025 23:20:28 +1000 Subject: [PATCH 1/3] Explicitly set black rectangle color --- lib/matplotlib/backends/_backend_tk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index df9e6027b88b..42782b2f00e1 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -769,7 +769,7 @@ def draw_rubberband(self, event, x0, y0, x1, y1): y1 = height - y1 self.canvas._rubberband_rect_black = ( self.canvas._tkcanvas.create_rectangle( - x0, y0, x1, y1)) + x0, y0, x1, y1, outline='black')) self.canvas._rubberband_rect_white = ( self.canvas._tkcanvas.create_rectangle( x0, y0, x1, y1, outline='white', dash=(3, 3))) From 9f122cff310d68c8f0273ab29110cc108523c433 Mon Sep 17 00:00:00 2001 From: Lucas Gruwez Date: Mon, 15 Sep 2025 17:39:23 +1000 Subject: [PATCH 2/3] Make WebAgg rubberband consistent with Qt backend Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/backends/web_backend/js/mpl.js | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backends/web_backend/js/mpl.js b/lib/matplotlib/backends/web_backend/js/mpl.js index f2bfc43bd0e4..7745cbcf1e98 100644 --- a/lib/matplotlib/backends/web_backend/js/mpl.js +++ b/lib/matplotlib/backends/web_backend/js/mpl.js @@ -325,7 +325,6 @@ mpl.figure.prototype._init_canvas = function () { canvas_div.appendChild(rubberband_canvas); this.rubberband_context = rubberband_canvas.getContext('2d'); - this.rubberband_context.strokeStyle = '#000000'; this._resize_canvas = function (width, height, forward) { if (forward) { @@ -469,19 +468,38 @@ mpl.figure.prototype.handle_rubberband = function (fig, msg) { y0 = Math.floor(y0) + 0.5; x1 = Math.floor(x1) + 0.5; y1 = Math.floor(y1) + 0.5; - var min_x = Math.min(x0, x1); - var min_y = Math.min(y0, y1); - var width = Math.abs(x1 - x0); - var height = Math.abs(y1 - y0); - fig.rubberband_context.clearRect( + var ctx = fig.rubberband_context; + ctx.clearRect( 0, 0, fig.canvas.width / fig.ratio, fig.canvas.height / fig.ratio ); - fig.rubberband_context.strokeRect(min_x, min_y, width, height); + var drawRubberband = function () { + // Draw the lines from x0, y0 towards x1, y1 so that the + // dashes don't "jump" when moving the zoom box. + ctx.beginPath(); + ctx.moveTo(x0, y0); + ctx.lineTo(x0, y1); + ctx.moveTo(x0, y0); + ctx.lineTo(x1, y0); + ctx.moveTo(x0, y1); + ctx.lineTo(x1, y1); + ctx.moveTo(x1, y0); + ctx.lineTo(x1, y1); + ctx.stroke(); + }; + + fig.rubberband_context.lineWidth = 1; + fig.rubberband_context.setLineDash([3]); + fig.rubberband_context.lineDashOffset = 0; + fig.rubberband_context.strokeStyle = '#000000'; + drawRubberband(); + fig.rubberband_context.strokeStyle = '#ffffff'; + fig.rubberband_context.lineDashOffset = 3; + drawRubberband(); }; mpl.figure.prototype.handle_figure_label = function (fig, msg) { From e4ef10311c11985944feb3dff273bb8ddc528250 Mon Sep 17 00:00:00 2001 From: Lucas Gruwez Date: Mon, 15 Sep 2025 17:43:10 +1000 Subject: [PATCH 3/3] What's new rst --- doc/release/next_whats_new/zoom_boxes.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/release/next_whats_new/zoom_boxes.rst diff --git a/doc/release/next_whats_new/zoom_boxes.rst b/doc/release/next_whats_new/zoom_boxes.rst new file mode 100644 index 000000000000..8cc0cc1645a3 --- /dev/null +++ b/doc/release/next_whats_new/zoom_boxes.rst @@ -0,0 +1,4 @@ +Consistent zoom boxes +--------------------- + +Zooming now has a consistent dashed box style across all backends.