2
2
# Created: 23 Sep 2005
3
3
# Parts rewritten by Reinier Heeres <[email protected] >
4
4
5
- import copy
6
-
7
5
import numpy as np
8
6
9
7
from matplotlib import (
12
10
from . import art3d , proj3d
13
11
14
12
13
+ @cbook .deprecated ("3.1" )
15
14
def get_flip_min_max (coord , index , mins , maxs ):
16
15
if coord [index ] == mins [index ]:
17
16
return maxs [index ]
@@ -20,16 +19,12 @@ def get_flip_min_max(coord, index, mins, maxs):
20
19
21
20
22
21
def move_from_center (coord , centers , deltas , axmask = (True , True , True )):
23
- '''Return a coordinate that is moved by "deltas" away from the center.'''
24
- coord = copy .copy (coord )
25
- for i in range (3 ):
26
- if not axmask [i ]:
27
- continue
28
- if coord [i ] < centers [i ]:
29
- coord [i ] -= deltas [i ]
30
- else :
31
- coord [i ] += deltas [i ]
32
- return coord
22
+ """
23
+ For each coordinate where *axmask* is True, move *coord* away from
24
+ *centers* by *deltas*.
25
+ """
26
+ coord = np .asarray (coord )
27
+ return coord + axmask * np .copysign (1 , coord - centers ) * deltas
33
28
34
29
35
30
def tick_update_position (tick , tickxs , tickys , labelpos ):
@@ -225,35 +220,35 @@ def draw(self, renderer):
225
220
226
221
# Determine grid lines
227
222
minmax = np .where (highs , maxs , mins )
223
+ maxmin = np .where (highs , mins , maxs )
228
224
229
225
# Draw main axis line
230
226
juggled = info ['juggled' ]
231
227
edgep1 = minmax .copy ()
232
- edgep1 [juggled [0 ]] = get_flip_min_max ( edgep1 , juggled [0 ], mins , maxs )
228
+ edgep1 [juggled [0 ]] = maxmin [ juggled [0 ]]
233
229
234
230
edgep2 = edgep1 .copy ()
235
- edgep2 [juggled [1 ]] = get_flip_min_max ( edgep2 , juggled [1 ], mins , maxs )
236
- pep = proj3d . proj_trans_points ([ edgep1 , edgep2 ], renderer . M )
237
- centpt = proj3d .proj_transform (
238
- centers [ 0 ], centers [ 1 ], centers [ 2 ] , renderer .M )
239
- self .line .set_data (( pep [0 ][ 0 ] , pep [0 ][ 1 ]), ( pep [ 1 ][ 0 ], pep [ 1 ][ 1 ]) )
231
+ edgep2 [juggled [1 ]] = maxmin [ juggled [1 ]]
232
+ pep = np . asarray (
233
+ proj3d .proj_trans_points ([ edgep1 , edgep2 ], renderer . M ))
234
+ centpt = proj3d . proj_transform ( * centers , renderer .M )
235
+ self .line .set_data (pep [0 ], pep [1 ] )
240
236
self .line .draw (renderer )
241
237
242
238
# Grid points where the planes meet
243
239
xyz0 = np .tile (minmax , (len (ticks ), 1 ))
244
240
xyz0 [:, index ] = [tick .get_loc () for tick in ticks ]
245
241
246
242
# Draw labels
247
- peparray = np .asanyarray (pep )
248
243
# The transAxes transform is used because the Text object
249
244
# rotates the text relative to the display coordinate system.
250
245
# Therefore, if we want the labels to remain parallel to the
251
246
# axis regardless of the aspect ratio, we need to convert the
252
247
# edge points of the plane to display coordinates and calculate
253
248
# an angle from that.
254
249
# TODO: Maybe Text objects should handle this themselves?
255
- dx , dy = (self .axes .transAxes .transform ([peparray [0 :2 , 1 ]]) -
256
- self .axes .transAxes .transform ([peparray [0 :2 , 0 ]]))[0 ]
250
+ dx , dy = (self .axes .transAxes .transform ([pep [0 :2 , 1 ]]) -
251
+ self .axes .transAxes .transform ([pep [0 :2 , 0 ]]))[0 ]
257
252
258
253
lxyz = 0.5 * (edgep1 + edgep2 )
259
254
@@ -268,8 +263,7 @@ def draw(self, renderer):
268
263
axmask = [True , True , True ]
269
264
axmask [index ] = False
270
265
lxyz = move_from_center (lxyz , centers , labeldeltas , axmask )
271
- tlx , tly , tlz = proj3d .proj_transform (lxyz [0 ], lxyz [1 ], lxyz [2 ],
272
- renderer .M )
266
+ tlx , tly , tlz = proj3d .proj_transform (* lxyz , renderer .M )
273
267
self .label .set_position ((tlx , tly ))
274
268
if self .get_rotate_label (self .label .get_text ()):
275
269
angle = art3d ._norm_text_angle (np .rad2deg (np .arctan2 (dy , dx )))
@@ -289,10 +283,9 @@ def draw(self, renderer):
289
283
outeredgep = edgep2
290
284
outerindex = 1
291
285
292
- pos = copy .copy (outeredgep )
286
+ pos = outeredgep .copy ()
293
287
pos = move_from_center (pos , centers , labeldeltas , axmask )
294
- olx , oly , olz = proj3d .proj_transform (
295
- pos [0 ], pos [1 ], pos [2 ], renderer .M )
288
+ olx , oly , olz = proj3d .proj_transform (* pos , renderer .M )
296
289
self .offsetText .set_text (self .major .formatter .get_offset ())
297
290
self .offsetText .set_position ((olx , oly ))
298
291
angle = art3d ._norm_text_angle (np .rad2deg (np .arctan2 (dy , dx )))
@@ -310,16 +303,16 @@ def draw(self, renderer):
310
303
# using the wrong reference points).
311
304
#
312
305
# (TT, FF, TF, FT) are the shorthand for the tuple of
313
- # (centpt[info['tickdir']] <= peparray [info['tickdir'], outerindex],
314
- # centpt[index] <= peparray [index, outerindex])
306
+ # (centpt[info['tickdir']] <= pep [info['tickdir'], outerindex],
307
+ # centpt[index] <= pep [index, outerindex])
315
308
#
316
309
# Three-letters (e.g., TFT, FTT) are short-hand for the array of bools
317
310
# from the variable 'highs'.
318
311
# ---------------------------------------------------------------------
319
- if centpt [info ['tickdir' ]] > peparray [info ['tickdir' ], outerindex ]:
312
+ if centpt [info ['tickdir' ]] > pep [info ['tickdir' ], outerindex ]:
320
313
# if FT and if highs has an even number of Trues
321
- if (centpt [index ] <= peparray [index , outerindex ]
322
- and len ( highs . nonzero ()[ 0 ] ) % 2 == 0 ):
314
+ if (centpt [index ] <= pep [index , outerindex ]
315
+ and np . count_nonzero ( highs ) % 2 == 0 ):
323
316
# Usually, this means align right, except for the FTT case,
324
317
# in which offset for axis 1 and 2 are aligned left.
325
318
if highs .tolist () == [False , True , True ] and index in (1 , 2 ):
@@ -331,8 +324,8 @@ def draw(self, renderer):
331
324
align = 'left'
332
325
else :
333
326
# if TF and if highs has an even number of Trues
334
- if (centpt [index ] > peparray [index , outerindex ]
335
- and len ( highs . nonzero ()[ 0 ] ) % 2 == 0 ):
327
+ if (centpt [index ] > pep [index , outerindex ]
328
+ and np . count_nonzero ( highs ) % 2 == 0 ):
336
329
# Usually mean align left, except if it is axis 2
337
330
if index == 2 :
338
331
align = 'right'
@@ -351,14 +344,12 @@ def draw(self, renderer):
351
344
# Grid points at end of one plane
352
345
xyz1 = xyz0 .copy ()
353
346
newindex = (index + 1 ) % 3
354
- newval = get_flip_min_max (xyz1 [0 ], newindex , mins , maxs )
355
- xyz1 [:, newindex ] = newval
347
+ xyz1 [:, newindex ] = maxmin [newindex ]
356
348
357
349
# Grid points at end of the other plane
358
350
xyz2 = xyz0 .copy ()
359
351
newindex = (index + 2 ) % 3
360
- newval = get_flip_min_max (xyz2 [0 ], newindex , mins , maxs )
361
- xyz2 [:, newindex ] = newval
352
+ xyz2 [:, newindex ] = maxmin [newindex ]
362
353
363
354
lines = np .stack ([xyz1 , xyz0 , xyz2 ], axis = 1 )
364
355
self .gridlines .set_segments (lines )
@@ -377,18 +368,16 @@ def draw(self, renderer):
377
368
378
369
for tick in ticks :
379
370
# Get tick line positions
380
- pos = copy .copy (edgep1 )
371
+ pos = edgep1 .copy ()
381
372
pos [index ] = tick .get_loc ()
382
373
pos [tickdir ] = (
383
374
edgep1 [tickdir ]
384
375
+ info ['tick' ]['outward_factor' ] * ticksign * tickdelta )
385
- x1 , y1 , z1 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
386
- renderer .M )
376
+ x1 , y1 , z1 = proj3d .proj_transform (* pos , renderer .M )
387
377
pos [tickdir ] = (
388
378
edgep1 [tickdir ]
389
379
- info ['tick' ]['inward_factor' ] * ticksign * tickdelta )
390
- x2 , y2 , z2 = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
391
- renderer .M )
380
+ x2 , y2 , z2 = proj3d .proj_transform (* pos , renderer .M )
392
381
393
382
# Get position of label
394
383
default_offset = 8. # A rough estimate
@@ -399,8 +388,7 @@ def draw(self, renderer):
399
388
axmask [index ] = False
400
389
pos [tickdir ] = edgep1 [tickdir ]
401
390
pos = move_from_center (pos , centers , labeldeltas , axmask )
402
- lx , ly , lz = proj3d .proj_transform (pos [0 ], pos [1 ], pos [2 ],
403
- renderer .M )
391
+ lx , ly , lz = proj3d .proj_transform (* pos , renderer .M )
404
392
405
393
tick_update_position (tick , (x1 , x2 ), (y1 , y2 ), (lx , ly ))
406
394
tick .tick1line .set_linewidth (info ['tick' ]['linewidth' ])
0 commit comments