8686# angles are given in data coordinate - need to convert it to canvas coordinate
8787
8888
89+ from operator import methodcaller
90+
8991import numpy as np
9092
9193from matplotlib import cbook , rcParams
@@ -161,34 +163,31 @@ class UnimplementedException(Exception):
161163
162164
163165class AttributeCopier :
166+ @cbook .deprecated ("3.2" )
164167 def __init__ (self , ref_artist , klass = Artist ):
165168 self ._klass = klass
166169 self ._ref_artist = ref_artist
167170 super ().__init__ ()
168171
172+ @cbook .deprecated ("3.2" )
169173 def set_ref_artist (self , artist ):
170174 self ._ref_artist = artist
171175
172176 def get_ref_artist (self ):
177+ """
178+ Return the underlying artist that actually defines some properties
179+ (e.g., color) of this artist.
180+ """
173181 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
187182
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
189188
190189
191- class Ticks (Line2D , AttributeCopier ):
190+ class Ticks (AttributeCopier , Line2D ):
192191 """
193192 Ticks are derived from Line2D, and note that ticks themselves
194193 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):
213212 kwargs ["markeredgewidth" ] = "auto"
214213
215214 Line2D .__init__ (self , [0. ], [0. ], ** kwargs )
216- AttributeCopier .__init__ (self , self ._axis , klass = Line2D )
217215 self .set_snap (True )
218216
219217 def get_ref_artist (self ):
220- return self ._ref_artist .majorTicks [0 ].tick1line
218+ # docstring inherited
219+ return self ._axis .majorTicks [0 ].tick1line
221220
222221 def get_color (self ):
223- return self .get_attribute_from_ref_artist ("color" , "k" )
222+ return self .get_attribute_from_ref_artist ("color" )
224223
225224 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" )
230226
231227 def get_markeredgewidth (self ):
232- return self .get_attribute_from_ref_artist ("markeredgewidth" , .5 )
228+ return self .get_attribute_from_ref_artist ("markeredgewidth" )
233229
234230 def set_tick_out (self , b ):
235231 """Set whether ticks are drawn inside or outside the axes."""
@@ -383,7 +379,7 @@ def get_window_extent(self, renderer):
383379 return bbox
384380
385381
386- class AxisLabel (LabelBase , AttributeCopier ):
382+ class AxisLabel (AttributeCopier , LabelBase ):
387383 """
388384 Axis Label. Derived from Text. The position of the text is updated
389385 in the fly, so changing text position has no effect. Otherwise, the
@@ -393,11 +389,8 @@ class AxisLabel(LabelBase, AttributeCopier):
393389 """
394390
395391 def __init__ (self , * args , axis_direction = "bottom" , axis = None , ** kwargs ):
396-
397392 self ._axis = axis
398393 LabelBase .__init__ (self , * args , ** kwargs )
399- AttributeCopier .__init__ (self , self ._axis , klass = LabelBase )
400-
401394 self .set_axis_direction (axis_direction )
402395 self ._pad = 5
403396 self ._extra_pad = 0
@@ -428,6 +421,7 @@ def _get_external_pad(self):
428421 return self ._extra_pad
429422
430423 def get_ref_artist (self ):
424+ # docstring inherited
431425 return self ._axis .get_label ()
432426
433427 def get_text (self ):
@@ -475,7 +469,7 @@ def set_axis_direction(self, d):
475469 self .set_default_angle (d )
476470
477471 def get_color (self ):
478- return self .get_attribute_from_ref_artist ("color" , "k" )
472+ return self .get_attribute_from_ref_artist ("color" )
479473
480474 def draw (self , renderer ):
481475 if not self .get_visible ():
@@ -500,7 +494,7 @@ def get_window_extent(self, renderer):
500494 return bb
501495
502496
503- class TickLabels (AxisLabel , AttributeCopier ): # mtext.Text
497+ class TickLabels (AxisLabel ): # mtext.Text
504498 """
505499 Tick Labels. While derived from Text, this single artist draws all
506500 ticklabels. As in AxisLabel, the position of the text is updated
@@ -517,8 +511,8 @@ def __init__(self, *, axis_direction="bottom", **kwargs):
517511 self .set_axis_direction (axis_direction )
518512 self ._axislabel_pad = 0
519513
520- # attribute copier
521514 def get_ref_artist (self ):
515+ # docstring inherited
522516 return self ._axis .get_ticklabels ()[0 ]
523517
524518 def set_axis_direction (self , label_direction ):
0 commit comments