86
86
# angles are given in data coordinate - need to convert it to canvas coordinate
87
87
88
88
89
+ from operator import methodcaller
90
+
89
91
import numpy as np
90
92
91
93
from matplotlib import cbook , rcParams
@@ -161,34 +163,31 @@ class UnimplementedException(Exception):
161
163
162
164
163
165
class AttributeCopier :
166
+ @cbook .deprecated ("3.2" )
164
167
def __init__ (self , ref_artist , klass = Artist ):
165
168
self ._klass = klass
166
169
self ._ref_artist = ref_artist
167
170
super ().__init__ ()
168
171
172
+ @cbook .deprecated ("3.2" )
169
173
def set_ref_artist (self , artist ):
170
174
self ._ref_artist = artist
171
175
172
176
def get_ref_artist (self ):
177
+ """
178
+ Return the underlying artist that actually defines some properties
179
+ (e.g., color) of this artist.
180
+ """
173
181
raise RuntimeError ("get_ref_artist must overridden" )
174
- #return self._ref_artist
175
-
176
- def get_attribute_from_ref_artist (self , attr_name , default_value ):
177
- get_attr_method_name = "get_" + attr_name
178
- c = getattr (self ._klass , get_attr_method_name )(self )
179
- if c == 'auto' :
180
- ref_artist = self .get_ref_artist ()
181
- if ref_artist :
182
- attr = getattr (ref_artist ,
183
- get_attr_method_name )()
184
- return attr
185
- else :
186
- return default_value
187
182
188
- return c
183
+ @cbook ._delete_parameter ("3.2" , "default_value" )
184
+ def get_attribute_from_ref_artist (self , attr_name , default_value = None ):
185
+ getter = methodcaller ("get_" + attr_name )
186
+ prop = getter (super ())
187
+ return getter (self .get_ref_artist ()) if prop == "auto" else prop
189
188
190
189
191
- class Ticks (Line2D , AttributeCopier ):
190
+ class Ticks (AttributeCopier , Line2D ):
192
191
"""
193
192
Ticks are derived from Line2D, and note that ticks themselves
194
193
are markers. Thus, you should use set_mec, set_mew, etc.
@@ -213,23 +212,20 @@ def __init__(self, ticksize, tick_out=False, *, axis=None, **kwargs):
213
212
kwargs ["markeredgewidth" ] = "auto"
214
213
215
214
Line2D .__init__ (self , [0. ], [0. ], ** kwargs )
216
- AttributeCopier .__init__ (self , self ._axis , klass = Line2D )
217
215
self .set_snap (True )
218
216
219
217
def get_ref_artist (self ):
220
- return self ._ref_artist .majorTicks [0 ].tick1line
218
+ # docstring inherited
219
+ return self ._axis .majorTicks [0 ].tick1line
221
220
222
221
def get_color (self ):
223
- return self .get_attribute_from_ref_artist ("color" , "k" )
222
+ return self .get_attribute_from_ref_artist ("color" )
224
223
225
224
def get_markeredgecolor (self ):
226
- if self ._markeredgecolor == 'auto' :
227
- return self .get_color ()
228
- else :
229
- return self ._markeredgecolor
225
+ return self .get_attribute_from_ref_artist ("markeredgecolor" )
230
226
231
227
def get_markeredgewidth (self ):
232
- return self .get_attribute_from_ref_artist ("markeredgewidth" , .5 )
228
+ return self .get_attribute_from_ref_artist ("markeredgewidth" )
233
229
234
230
def set_tick_out (self , b ):
235
231
"""Set whether ticks are drawn inside or outside the axes."""
@@ -383,7 +379,7 @@ def get_window_extent(self, renderer):
383
379
return bbox
384
380
385
381
386
- class AxisLabel (LabelBase , AttributeCopier ):
382
+ class AxisLabel (AttributeCopier , LabelBase ):
387
383
"""
388
384
Axis Label. Derived from Text. The position of the text is updated
389
385
in the fly, so changing text position has no effect. Otherwise, the
@@ -393,11 +389,8 @@ class AxisLabel(LabelBase, AttributeCopier):
393
389
"""
394
390
395
391
def __init__ (self , * args , axis_direction = "bottom" , axis = None , ** kwargs ):
396
-
397
392
self ._axis = axis
398
393
LabelBase .__init__ (self , * args , ** kwargs )
399
- AttributeCopier .__init__ (self , self ._axis , klass = LabelBase )
400
-
401
394
self .set_axis_direction (axis_direction )
402
395
self ._pad = 5
403
396
self ._extra_pad = 0
@@ -428,6 +421,7 @@ def _get_external_pad(self):
428
421
return self ._extra_pad
429
422
430
423
def get_ref_artist (self ):
424
+ # docstring inherited
431
425
return self ._axis .get_label ()
432
426
433
427
def get_text (self ):
@@ -475,7 +469,7 @@ def set_axis_direction(self, d):
475
469
self .set_default_angle (d )
476
470
477
471
def get_color (self ):
478
- return self .get_attribute_from_ref_artist ("color" , "k" )
472
+ return self .get_attribute_from_ref_artist ("color" )
479
473
480
474
def draw (self , renderer ):
481
475
if not self .get_visible ():
@@ -500,7 +494,7 @@ def get_window_extent(self, renderer):
500
494
return bb
501
495
502
496
503
- class TickLabels (AxisLabel , AttributeCopier ): # mtext.Text
497
+ class TickLabels (AxisLabel ): # mtext.Text
504
498
"""
505
499
Tick Labels. While derived from Text, this single artist draws all
506
500
ticklabels. As in AxisLabel, the position of the text is updated
@@ -517,8 +511,8 @@ def __init__(self, *, axis_direction="bottom", **kwargs):
517
511
self .set_axis_direction (axis_direction )
518
512
self ._axislabel_pad = 0
519
513
520
- # attribute copier
521
514
def get_ref_artist (self ):
515
+ # docstring inherited
522
516
return self ._axis .get_ticklabels ()[0 ]
523
517
524
518
def set_axis_direction (self , label_direction ):
0 commit comments