2424
2525
2626def _process_text_args (override , fontdict = None , ** kwargs ):
27- "Return an override dict. See :func: `~pyplot.text' docstring for info"
27+ """ Return an override dict. See `~pyplot.text' docstring for info."" "
2828
2929 if fontdict is not None :
3030 override .update (fontdict )
@@ -51,24 +51,21 @@ def _wrap_text(textobj):
5151# Extracted from Text's method to serve as a function
5252def get_rotation (rotation ):
5353 """
54- Return the text angle as float. The returned
55- angle is between 0 and 360 deg.
54+ Return the text angle as float between 0 and 360 degrees.
5655
5756 *rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
5857 """
5958 try :
60- angle = float (rotation )
59+ return float (rotation ) % 360
6160 except (ValueError , TypeError ):
6261 if cbook ._str_equal (rotation , 'horizontal' ) or rotation is None :
63- angle = 0.
62+ return 0.
6463 elif cbook ._str_equal (rotation , 'vertical' ):
65- angle = 90.
64+ return 90.
6665 else :
67- raise ValueError ("rotation is {0} expected either 'horizontal'"
68- " 'vertical', numeric value or"
69- "None" .format (rotation ))
70-
71- return angle % 360
66+ raise ValueError ("rotation is {!r}; expected either 'horizontal', "
67+ "'vertical', numeric value, or None"
68+ .format (rotation ))
7269
7370
7471def _get_textbox (text , renderer ):
@@ -104,9 +101,7 @@ def _get_textbox(text, renderer):
104101 xt_box , yt_box = min (projected_xs ), min (projected_ys )
105102 w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
106103
107- tr = Affine2D ().rotate (theta )
108-
109- x_box , y_box = tr .transform_point ((xt_box , yt_box ))
104+ x_box , y_box = Affine2D ().rotate (theta ).transform_point ((xt_box , yt_box ))
110105
111106 return x_box , y_box , w_box , h_box
112107
@@ -230,7 +225,9 @@ def contains(self, mouseevent):
230225 return inside , cattr
231226
232227 def _get_xy_display (self ):
233- 'get the (possibly unit converted) transformed x, y in display coords'
228+ """
229+ Get the (possibly unit converted) transformed x, y in display coords.
230+ """
234231 x , y = self .get_unitless_position ()
235232 return self .get_transform ().transform_point ((x , y ))
236233
@@ -241,7 +238,7 @@ def _get_multialignment(self):
241238 return self ._horizontalalignment
242239
243240 def get_rotation (self ):
244- 'return the text angle as float in degrees'
241+ """Return the text angle as float in degrees."""
245242 return get_rotation (self ._rotation ) # string_or_number -> number
246243
247244 def set_rotation_mode (self , m ):
@@ -264,11 +261,11 @@ def set_rotation_mode(self, m):
264261 self .stale = True
265262
266263 def get_rotation_mode (self ):
267- "get text rotation mode"
264+ """Get the text rotation mode."" "
268265 return self ._rotation_mode
269266
270267 def update_from (self , other ):
271- ' Copy properties from other to self'
268+ """ Copy properties from other to self."""
272269 Artist .update_from (self , other )
273270 self ._color = other ._color
274271 self ._multialignment = other ._multialignment
@@ -479,16 +476,16 @@ def set_bbox(self, rectprops):
479476
480477 def get_bbox_patch (self ):
481478 """
482- Return the bbox Patch object. Returns None if the
483- FancyBboxPatch is not made.
479+ Return the bbox Patch, or None if the FancyBboxPatch is not made.
484480 """
485481 return self ._bbox_patch
486482
487483 def update_bbox_position_size (self , renderer ):
488484 """
489- Update the location and the size of the bbox. This method
490- should be used when the position and size of the bbox needs to
491- be updated before actually drawing the bbox.
485+ Update the location and the size of the bbox.
486+
487+ This method should be used when the position and size of the bbox needs
488+ to be updated before actually drawing the bbox.
492489 """
493490
494491 if self ._bbox_patch :
@@ -512,9 +509,8 @@ def update_bbox_position_size(self, renderer):
512509 self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
513510
514511 def _draw_bbox (self , renderer , posx , posy ):
515-
516- """ Update the location and the size of the bbox
517- (FancyBboxPatch), and draw
512+ """
513+ Update the location and size of the bbox (FancyBboxPatch), and draw.
518514 """
519515
520516 x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
@@ -531,7 +527,6 @@ def _update_clip_properties(self):
531527 clipprops = dict (clip_box = self .clipbox ,
532528 clip_path = self ._clippath ,
533529 clip_on = self ._clipon )
534-
535530 if self ._bbox_patch :
536531 bbox = self ._bbox_patch .update (clipprops )
537532
@@ -584,11 +579,11 @@ def set_clip_on(self, b):
584579 self ._update_clip_properties ()
585580
586581 def get_wrap (self ):
587- """Returns the wrapping state for the text."""
582+ """Return the wrapping state for the text."""
588583 return self ._wrap
589584
590585 def set_wrap (self , wrap ):
591- """Sets the wrapping state for the text.
586+ """Set the wrapping state for the text.
592587
593588 Parameters
594589 ----------
@@ -599,8 +594,8 @@ def set_wrap(self, wrap):
599594
600595 def _get_wrap_line_width (self ):
601596 """
602- Returns the maximum line width for wrapping text based on the
603- current orientation.
597+ Return the maximum line width for wrapping text based on the current
598+ orientation.
604599 """
605600 x0 , y0 = self .get_transform ().transform (self .get_position ())
606601 figure_box = self .get_figure ().get_window_extent ()
@@ -612,10 +607,7 @@ def _get_wrap_line_width(self):
612607
613608 left = self ._get_dist_to_box (rotation , x0 , y0 , figure_box )
614609 right = self ._get_dist_to_box (
615- (180 + rotation ) % 360 ,
616- x0 ,
617- y0 ,
618- figure_box )
610+ (180 + rotation ) % 360 , x0 , y0 , figure_box )
619611
620612 if alignment == 'left' :
621613 line_width = left
@@ -628,8 +620,8 @@ def _get_wrap_line_width(self):
628620
629621 def _get_dist_to_box (self , rotation , x0 , y0 , figure_box ):
630622 """
631- Returns the distance from the given points, to the boundaries
632- of a rotated box in pixels.
623+ Return the distance from the given points to the boundaries of a
624+ rotated box, in pixels.
633625 """
634626 if rotation > 270 :
635627 quad = rotation - 270
@@ -651,7 +643,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
651643
652644 def _get_rendered_text_width (self , text ):
653645 """
654- Returns the width of a given text string, in pixels.
646+ Return the width of a given text string, in pixels.
655647 """
656648 w , h , d = self ._renderer .get_text_width_height_descent (
657649 text ,
@@ -1226,7 +1218,7 @@ class TextWithDash(Text):
12261218 __name__ = 'textwithdash'
12271219
12281220 def __str__ (self ):
1229- return "TextWithDash(%g,%g,%s )" % (self ._x , self ._y , repr ( self ._text ) )
1221+ return "TextWithDash(%g, %g, %r )" % (self ._x , self ._y , self ._text )
12301222
12311223 def __init__ (self ,
12321224 x = 0 , y = 0 , text = '' ,
@@ -1853,9 +1845,7 @@ def draggable(self, state=None, use_blit=False):
18531845
18541846class Annotation (Text , _AnnotationBase ):
18551847 def __str__ (self ):
1856- return "Annotation(%g,%g,%s)" % (self .xy [0 ],
1857- self .xy [1 ],
1858- repr (self ._text ))
1848+ return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
18591849
18601850 @docstring .dedent_interpd
18611851 def __init__ (self , s , xy ,
@@ -1874,10 +1864,10 @@ def __init__(self, s, xy,
18741864 ----------
18751865
18761866 s : str
1877- The text of the annotation
1867+ The text of the annotation.
18781868
18791869 xy : iterable
1880- Length 2 sequence specifying the *(x,y)* point to annotate
1870+ Length 2 sequence specifying the *(x,y)* point to annotate.
18811871
18821872 xytext : iterable, optional
18831873 Length 2 sequence specifying the *(x,y)* to place the text
@@ -2087,15 +2077,13 @@ def set_figure(self, fig):
20872077 Artist .set_figure (self , fig )
20882078
20892079 def update_positions (self , renderer ):
2090- """"Update the pixel positions of the annotated point and the
2091- text.
2092- """
2080+ """Update the pixel positions of the annotated point and the text."""
20932081 xy_pixel = self ._get_position_xy (renderer )
20942082 self ._update_position_xytext (renderer , xy_pixel )
20952083
20962084 def _update_position_xytext (self , renderer , xy_pixel ):
2097- """Update the pixel positions of the annotation text and the arrow
2098- patch.
2085+ """
2086+ Update the pixel positions of the annotation text and the arrow patch.
20992087 """
21002088 # generate transformation,
21012089 self .set_transform (self ._get_xy_transform (renderer , self .anncoords ))
@@ -2234,7 +2222,6 @@ def get_window_extent(self, renderer=None):
22342222 simpler to call the method after saving the figure. The
22352223 *dpi* used defaults to self.figure.dpi; the renderer dpi is
22362224 irrelevant.
2237-
22382225 '''
22392226 if not self .get_visible ():
22402227 return Bbox .unit ()
0 commit comments