@@ -52,6 +52,7 @@ def _mpl_to_gtk_cursor(mpl_cursor):
5252class FigureCanvasGTK4 (Gtk .DrawingArea , FigureCanvasBase ):
5353 required_interactive_framework = "gtk4"
5454 _timer_cls = TimerGTK4
55+ _context_is_scaled = False
5556
5657 def __init__ (self , figure = None ):
5758 FigureCanvasBase .__init__ (self , figure )
@@ -205,8 +206,15 @@ def _post_draw(self, widget, ctx):
205206 if self ._rubberband_rect is None :
206207 return
207208
208- x0 , y0 , w , h = (dim / self .device_pixel_ratio
209- for dim in self ._rubberband_rect )
209+ lw = 1
210+ dash = 3
211+ if not self ._context_is_scaled :
212+ x0 , y0 , w , h = (dim / self .device_pixel_ratio
213+ for dim in self ._rubberband_rect )
214+ else :
215+ x0 , y0 , w , h = self ._rubberband_rect
216+ lw *= self .device_pixel_ratio
217+ dash *= self .device_pixel_ratio
210218 x1 = x0 + w
211219 y1 = y0 + h
212220
@@ -222,12 +230,12 @@ def _post_draw(self, widget, ctx):
222230 ctx .line_to (x1 , y1 )
223231
224232 ctx .set_antialias (1 )
225- ctx .set_line_width (1 )
226- ctx .set_dash ((3 , 3 ), 0 )
233+ ctx .set_line_width (lw )
234+ ctx .set_dash ((dash , dash ), 0 )
227235 ctx .set_source_rgb (0 , 0 , 0 )
228236 ctx .stroke_preserve ()
229237
230- ctx .set_dash ((3 , 3 ), 3 )
238+ ctx .set_dash ((dash , dash ), dash )
231239 ctx .set_source_rgb (1 , 1 , 1 )
232240 ctx .stroke ()
233241
0 commit comments