@@ -69,16 +69,21 @@ def __init__(
69
69
self .set_viewport_rect ()
70
70
71
71
def get_rect (self ):
72
- i , j = self .position
73
- w , h = self .renderer .logical_size
72
+ row_ix , col_ix = self .position
73
+ width_canvas , height_canvas = self .renderer .logical_size
74
74
75
75
spacing = 2 # spacing in pixels
76
76
77
+ x_pos = ((width_canvas / self .ncols ) + ((col_ix - 1 ) * (width_canvas / self .ncols ))) + spacing
78
+ y_pos = ((height_canvas / self .nrows ) + ((row_ix - 1 ) * (height_canvas / self .nrows ))) + spacing
79
+ width_subplot = (width_canvas / self .ncols ) - spacing
80
+ height_suplot = (height_canvas / self .nrows ) - spacing
81
+
77
82
return np .array ([
78
- (( w / self . ncols ) + (( j - 1 ) * ( w / self . ncols ))) + spacing ,
79
- (( h / self . nrows ) + (( i - 1 ) * ( h / self . nrows ))) + spacing ,
80
- ( w / self . ncols ) - spacing ,
81
- ( h / self . nrows ) - spacing
83
+ x_pos ,
84
+ y_pos ,
85
+ width_subplot ,
86
+ height_suplot
82
87
])
83
88
84
89
def set_viewport_rect (self , * args ):
@@ -214,46 +219,38 @@ def _get_rect(self, *args):
214
219
self .viewport .rect = None
215
220
return
216
221
217
- i , j = self .parent .position
218
- w , h = self .parent .renderer .logical_size
222
+ row_ix_parent , col_ix_parent = self .parent .position
223
+ width_canvas , height_canvas = self .parent .renderer .logical_size
219
224
220
225
spacing = 2 # spacing in pixels
221
226
222
227
if self .position == "right" :
223
- r = [
224
- (w / self .parent .ncols ) + ((j - 1 ) * (w / self .parent .ncols )) + (w / self .parent .ncols ) - self .size ,
225
- ((h / self .parent .nrows ) + ((i - 1 ) * (h / self .parent .nrows ))) + spacing ,
226
- self .size ,
227
- (h / self .parent .nrows ) - spacing
228
- ]
228
+ x_pos = (width_canvas / self .parent .ncols ) + ((col_ix_parent - 1 ) * (width_canvas / self .parent .ncols )) + (width_canvas / self .parent .ncols ) - self .size
229
+ y_pos = ((height_canvas / self .parent .nrows ) + ((row_ix_parent - 1 ) * (height_canvas / self .parent .nrows ))) + spacing
230
+ width_viewport = self .size
231
+ height_viewport = (height_canvas / self .parent .nrows ) - spacing
229
232
230
233
elif self .position == "left" :
231
- r = [
232
- (w / self .parent .ncols ) + ((j - 1 ) * (w / self .parent .ncols )),
233
- ((h / self .parent .nrows ) + ((i - 1 ) * (h / self .parent .nrows ))) + spacing ,
234
- self .size ,
235
- (h / self .parent .nrows ) - spacing
236
- ]
234
+ x_pos = (width_canvas / self .parent .ncols ) + ((col_ix_parent - 1 ) * (width_canvas / self .parent .ncols ))
235
+ y_pos = ((height_canvas / self .parent .nrows ) + ((row_ix_parent - 1 ) * (height_canvas / self .parent .nrows ))) + spacing
236
+ width_viewport = self .size
237
+ height_viewport = (height_canvas / self .parent .nrows ) - spacing
237
238
238
239
elif self .position == "top" :
239
- r = [
240
- (w / self .parent .ncols ) + ((j - 1 ) * (w / self .parent .ncols )) + spacing ,
241
- ((h / self .parent .nrows ) + ((i - 1 ) * (h / self .parent .nrows ))) + spacing ,
242
- (w / self .parent .ncols ) - spacing ,
243
- self .size
244
- ]
240
+ x_pos = (width_canvas / self .parent .ncols ) + ((col_ix_parent - 1 ) * (width_canvas / self .parent .ncols )) + spacing
241
+ y_pos = ((height_canvas / self .parent .nrows ) + ((row_ix_parent - 1 ) * (height_canvas / self .parent .nrows ))) + spacing
242
+ width_viewport = (width_canvas / self .parent .ncols ) - spacing
243
+ height_viewport = self .size
245
244
246
245
elif self .position == "bottom" :
247
- r = [
248
- (w / self .parent .ncols ) + ((j - 1 ) * (w / self .parent .ncols )) + spacing ,
249
- ((h / self .parent .nrows ) + ((i - 1 ) * (h / self .parent .nrows ))) + (h / self .parent .nrows ) - self .size ,
250
- (w / self .parent .ncols ) - spacing ,
251
- self .size
252
- ]
246
+ x_pos = (width_canvas / self .parent .ncols ) + ((col_ix_parent - 1 ) * (width_canvas / self .parent .ncols )) + spacing
247
+ y_pos = ((height_canvas / self .parent .nrows ) + ((row_ix_parent - 1 ) * (height_canvas / self .parent .nrows ))) + (height_canvas / self .parent .nrows ) - self .size
248
+ width_viewport = (width_canvas / self .parent .ncols ) - spacing
249
+ height_viewport = self .size
253
250
else :
254
251
raise ValueError ("invalid position" )
255
252
256
- return r
253
+ return [ x_pos , y_pos , width_viewport , height_viewport ]
257
254
258
255
def set_viewport_rect (self , * args ):
259
256
rect = self ._get_rect ()
0 commit comments