22# Created: 23 Sep 2005
33# Parts rewritten by Reinier Heeres <[email protected] > 44
5- import copy
6-
75import numpy as np
86
97from matplotlib import (
1210from . import art3d , proj3d
1311
1412
13+ @cbook .deprecated ("3.1" )
1514def get_flip_min_max (coord , index , mins , maxs ):
1615 if coord [index ] == mins [index ]:
1716 return maxs [index ]
@@ -20,16 +19,12 @@ def get_flip_min_max(coord, index, mins, maxs):
2019
2120
2221def 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
3328
3429
3530def tick_update_position (tick , tickxs , tickys , labelpos ):
@@ -225,35 +220,35 @@ def draw(self, renderer):
225220
226221 # Determine grid lines
227222 minmax = np .where (highs , maxs , mins )
223+ maxmin = np .where (highs , mins , maxs )
228224
229225 # Draw main axis line
230226 juggled = info ['juggled' ]
231227 edgep1 = minmax .copy ()
232- edgep1 [juggled [0 ]] = get_flip_min_max ( edgep1 , juggled [0 ], mins , maxs )
228+ edgep1 [juggled [0 ]] = maxmin [ juggled [0 ]]
233229
234230 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 ] )
240236 self .line .draw (renderer )
241237
242238 # Grid points where the planes meet
243239 xyz0 = np .tile (minmax , (len (ticks ), 1 ))
244240 xyz0 [:, index ] = [tick .get_loc () for tick in ticks ]
245241
246242 # Draw labels
247- peparray = np .asanyarray (pep )
248243 # The transAxes transform is used because the Text object
249244 # rotates the text relative to the display coordinate system.
250245 # Therefore, if we want the labels to remain parallel to the
251246 # axis regardless of the aspect ratio, we need to convert the
252247 # edge points of the plane to display coordinates and calculate
253248 # an angle from that.
254249 # 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 ]
257252
258253 lxyz = 0.5 * (edgep1 + edgep2 )
259254
@@ -268,8 +263,7 @@ def draw(self, renderer):
268263 axmask = [True , True , True ]
269264 axmask [index ] = False
270265 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 )
273267 self .label .set_position ((tlx , tly ))
274268 if self .get_rotate_label (self .label .get_text ()):
275269 angle = art3d ._norm_text_angle (np .rad2deg (np .arctan2 (dy , dx )))
@@ -289,10 +283,9 @@ def draw(self, renderer):
289283 outeredgep = edgep2
290284 outerindex = 1
291285
292- pos = copy .copy (outeredgep )
286+ pos = outeredgep .copy ()
293287 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 )
296289 self .offsetText .set_text (self .major .formatter .get_offset ())
297290 self .offsetText .set_position ((olx , oly ))
298291 angle = art3d ._norm_text_angle (np .rad2deg (np .arctan2 (dy , dx )))
@@ -310,16 +303,16 @@ def draw(self, renderer):
310303 # using the wrong reference points).
311304 #
312305 # (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])
315308 #
316309 # Three-letters (e.g., TFT, FTT) are short-hand for the array of bools
317310 # from the variable 'highs'.
318311 # ---------------------------------------------------------------------
319- if centpt [info ['tickdir' ]] > peparray [info ['tickdir' ], outerindex ]:
312+ if centpt [info ['tickdir' ]] > pep [info ['tickdir' ], outerindex ]:
320313 # 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 ):
323316 # Usually, this means align right, except for the FTT case,
324317 # in which offset for axis 1 and 2 are aligned left.
325318 if highs .tolist () == [False , True , True ] and index in (1 , 2 ):
@@ -331,8 +324,8 @@ def draw(self, renderer):
331324 align = 'left'
332325 else :
333326 # 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 ):
336329 # Usually mean align left, except if it is axis 2
337330 if index == 2 :
338331 align = 'right'
@@ -351,14 +344,12 @@ def draw(self, renderer):
351344 # Grid points at end of one plane
352345 xyz1 = xyz0 .copy ()
353346 newindex = (index + 1 ) % 3
354- newval = get_flip_min_max (xyz1 [0 ], newindex , mins , maxs )
355- xyz1 [:, newindex ] = newval
347+ xyz1 [:, newindex ] = maxmin [newindex ]
356348
357349 # Grid points at end of the other plane
358350 xyz2 = xyz0 .copy ()
359351 newindex = (index + 2 ) % 3
360- newval = get_flip_min_max (xyz2 [0 ], newindex , mins , maxs )
361- xyz2 [:, newindex ] = newval
352+ xyz2 [:, newindex ] = maxmin [newindex ]
362353
363354 lines = np .stack ([xyz1 , xyz0 , xyz2 ], axis = 1 )
364355 self .gridlines .set_segments (lines )
@@ -377,18 +368,16 @@ def draw(self, renderer):
377368
378369 for tick in ticks :
379370 # Get tick line positions
380- pos = copy .copy (edgep1 )
371+ pos = edgep1 .copy ()
381372 pos [index ] = tick .get_loc ()
382373 pos [tickdir ] = (
383374 edgep1 [tickdir ]
384375 + 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 )
387377 pos [tickdir ] = (
388378 edgep1 [tickdir ]
389379 - 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 )
392381
393382 # Get position of label
394383 default_offset = 8. # A rough estimate
@@ -399,8 +388,7 @@ def draw(self, renderer):
399388 axmask [index ] = False
400389 pos [tickdir ] = edgep1 [tickdir ]
401390 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 )
404392
405393 tick_update_position (tick , (x1 , x2 ), (y1 , y2 ), (lx , ly ))
406394 tick .tick1line .set_linewidth (info ['tick' ]['linewidth' ])
0 commit comments