@@ -96,8 +96,10 @@ def init3d(self):
96
96
self .gridlines = art3d .Line3DCollection ([], )
97
97
self .axes ._set_artist_props (self .gridlines )
98
98
self .axes ._set_artist_props (self .label )
99
+ self .axes ._set_artist_props (self .offsetText )
99
100
# Need to be able to place the label at the correct location
100
101
self .label ._transform = self .axes .transData
102
+ self .offsetText ._transform = self .axes .transData
101
103
102
104
def get_tick_positions (self ):
103
105
majorLocs = self .major .locator ()
@@ -205,6 +207,7 @@ def draw(self, renderer):
205
207
edgep2 = edgep1 .copy ()
206
208
edgep2 [juggled [1 ]] = get_flip_min_max (edgep2 , juggled [1 ], mins , maxs )
207
209
pep = proj3d .proj_trans_points ([edgep1 , edgep2 ], renderer .M )
210
+ centpt = proj3d .proj_transform (centers [0 ], centers [1 ], centers [2 ], renderer .M )
208
211
self .line .set_data ((pep [0 ][0 ], pep [0 ][1 ]), (pep [1 ][0 ], pep [1 ][1 ]))
209
212
self .line .draw (renderer )
210
213
@@ -243,6 +246,75 @@ def draw(self, renderer):
243
246
self .label .set_ha ('center' )
244
247
self .label .draw (renderer )
245
248
249
+
250
+ # Draw Offset text
251
+
252
+ # Which of the two edge points do we want to
253
+ # use for locating the offset text?
254
+ if juggled [2 ] == 2 :
255
+ outeredgep = edgep1
256
+ outerindex = 0
257
+ else :
258
+ outeredgep = edgep2
259
+ outerindex = 1
260
+
261
+ pos = copy .copy (outeredgep )
262
+ pos = move_from_center (pos , centers , labeldeltas , axmask )
263
+ olx , oly , olz = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ], renderer .M )
264
+ self .offsetText .set_text ( self .major .formatter .get_offset () )
265
+ self .offsetText .set_position ( (olx , oly ) )
266
+ angle = art3d .norm_text_angle (math .degrees (math .atan2 (dy , dx )))
267
+ self .offsetText .set_rotation (angle )
268
+ # Must set rotation mode to "anchor" so that
269
+ # the alignment point is used as the "fulcrum" for rotation.
270
+ self .offsetText .set_rotation_mode ('anchor' )
271
+
272
+ #-----------------------------------------------------------------------
273
+ # Note: the following statement for determining the proper alignment of
274
+ # the offset text. This was determined entirely by trial-and-error
275
+ # and should not be in any way considered as "the way". There are
276
+ # still some edge cases where alignment is not quite right, but
277
+ # this seems to be more of a geometry issue (in other words, I
278
+ # might be using the wrong reference points).
279
+ #
280
+ # (TT, FF, TF, FT) are the shorthand for the tuple of
281
+ # (centpt[info['tickdir']] <= peparray[info['tickdir'], outerindex],
282
+ # centpt[index] <= peparray[index, outerindex])
283
+ #
284
+ # Three-letters (e.g., TFT, FTT) are short-hand for the array
285
+ # of bools from the variable 'highs'.
286
+ # ---------------------------------------------------------------------
287
+ if centpt [info ['tickdir' ]] > peparray [info ['tickdir' ], outerindex ] :
288
+ # if FT and if highs has an even number of Trues
289
+ if (centpt [index ] <= peparray [index , outerindex ]
290
+ and ((len (highs .nonzero ()[0 ]) % 2 ) == 0 )) :
291
+ # Usually, this means align right, except for the FTT case,
292
+ # in which offset for axis 1 and 2 are aligned left.
293
+ if highs .tolist () == [False , True , True ] and index in (1 , 2 ) :
294
+ align = 'left'
295
+ else :
296
+ align = 'right'
297
+ else :
298
+ # The FF case
299
+ align = 'left'
300
+ else :
301
+ # if TF and if highs has an even number of Trues
302
+ if (centpt [index ] > peparray [index , outerindex ]
303
+ and ((len (highs .nonzero ()[0 ]) % 2 ) == 0 )) :
304
+ # Usually mean align left, except if it is axis 2
305
+ if index == 2 :
306
+ align = 'right'
307
+ else :
308
+ align = 'left'
309
+ else :
310
+ # The TT case
311
+ align = 'right'
312
+
313
+ self .offsetText .set_va ('center' )
314
+ self .offsetText .set_ha (align )
315
+ self .offsetText .draw (renderer )
316
+
317
+ # Draw grid lines
246
318
if len (xyz0 ) > 0 :
247
319
# Grid points at end of one plane
248
320
xyz1 = copy .deepcopy (xyz0 )
0 commit comments