24
24
25
25
26
26
def _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."" "
28
28
29
29
if fontdict is not None :
30
30
override .update (fontdict )
@@ -51,24 +51,21 @@ def _wrap_text(textobj):
51
51
# Extracted from Text's method to serve as a function
52
52
def get_rotation (rotation ):
53
53
"""
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.
56
55
57
56
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
58
57
"""
59
58
try :
60
- angle = float (rotation )
59
+ return float (rotation ) % 360
61
60
except (ValueError , TypeError ):
62
61
if cbook ._str_equal (rotation , 'horizontal' ) or rotation is None :
63
62
angle = 0.
64
63
elif cbook ._str_equal (rotation , 'vertical' ):
65
64
angle = 90.
66
65
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 ))
72
69
73
70
74
71
def _get_textbox (text , renderer ):
@@ -104,9 +101,7 @@ def _get_textbox(text, renderer):
104
101
xt_box , yt_box = min (projected_xs ), min (projected_ys )
105
102
w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
106
103
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 ))
110
105
111
106
return x_box , y_box , w_box , h_box
112
107
@@ -230,7 +225,9 @@ def contains(self, mouseevent):
230
225
return inside , cattr
231
226
232
227
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
+ """
234
231
x , y = self .get_unitless_position ()
235
232
return self .get_transform ().transform_point ((x , y ))
236
233
@@ -241,7 +238,7 @@ def _get_multialignment(self):
241
238
return self ._horizontalalignment
242
239
243
240
def get_rotation (self ):
244
- 'return the text angle as float in degrees'
241
+ """Return the text angle as float in degrees."""
245
242
return get_rotation (self ._rotation ) # string_or_number -> number
246
243
247
244
def set_rotation_mode (self , m ):
@@ -264,11 +261,11 @@ def set_rotation_mode(self, m):
264
261
self .stale = True
265
262
266
263
def get_rotation_mode (self ):
267
- "get text rotation mode"
264
+ """Get text rotation mode."" "
268
265
return self ._rotation_mode
269
266
270
267
def update_from (self , other ):
271
- ' Copy properties from other to self'
268
+ """ Copy properties from other to self."""
272
269
Artist .update_from (self , other )
273
270
self ._color = other ._color
274
271
self ._multialignment = other ._multialignment
@@ -479,16 +476,16 @@ def set_bbox(self, rectprops):
479
476
480
477
def get_bbox_patch (self ):
481
478
"""
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.
484
480
"""
485
481
return self ._bbox_patch
486
482
487
483
def update_bbox_position_size (self , renderer ):
488
484
"""
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.
492
489
"""
493
490
494
491
if self ._bbox_patch :
@@ -512,9 +509,8 @@ def update_bbox_position_size(self, renderer):
512
509
self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
513
510
514
511
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.
518
514
"""
519
515
520
516
x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
@@ -531,7 +527,6 @@ def _update_clip_properties(self):
531
527
clipprops = dict (clip_box = self .clipbox ,
532
528
clip_path = self ._clippath ,
533
529
clip_on = self ._clipon )
534
-
535
530
if self ._bbox_patch :
536
531
bbox = self ._bbox_patch .update (clipprops )
537
532
@@ -584,11 +579,11 @@ def set_clip_on(self, b):
584
579
self ._update_clip_properties ()
585
580
586
581
def get_wrap (self ):
587
- """Returns the wrapping state for the text."""
582
+ """Return the wrapping state for the text."""
588
583
return self ._wrap
589
584
590
585
def set_wrap (self , wrap ):
591
- """Sets the wrapping state for the text.
586
+ """Set the wrapping state for the text.
592
587
593
588
Parameters
594
589
----------
@@ -599,8 +594,8 @@ def set_wrap(self, wrap):
599
594
600
595
def _get_wrap_line_width (self ):
601
596
"""
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.
604
599
"""
605
600
x0 , y0 = self .get_transform ().transform (self .get_position ())
606
601
figure_box = self .get_figure ().get_window_extent ()
@@ -612,10 +607,7 @@ def _get_wrap_line_width(self):
612
607
613
608
left = self ._get_dist_to_box (rotation , x0 , y0 , figure_box )
614
609
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 )
619
611
620
612
if alignment == 'left' :
621
613
line_width = left
@@ -628,8 +620,8 @@ def _get_wrap_line_width(self):
628
620
629
621
def _get_dist_to_box (self , rotation , x0 , y0 , figure_box ):
630
622
"""
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.
633
625
"""
634
626
if rotation > 270 :
635
627
quad = rotation - 270
@@ -651,7 +643,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
651
643
652
644
def _get_rendered_text_width (self , text ):
653
645
"""
654
- Returns the width of a given text string, in pixels.
646
+ Return the width of a given text string, in pixels.
655
647
"""
656
648
w , h , d = self ._renderer .get_text_width_height_descent (
657
649
text ,
@@ -1227,7 +1219,7 @@ class TextWithDash(Text):
1227
1219
__name__ = 'textwithdash'
1228
1220
1229
1221
def __str__ (self ):
1230
- return "TextWithDash(%g,%g,%s )" % (self ._x , self ._y , repr ( self ._text ) )
1222
+ return "TextWithDash(%g, %g, %r )" % (self ._x , self ._y , self ._text )
1231
1223
1232
1224
def __init__ (self ,
1233
1225
x = 0 , y = 0 , text = '' ,
@@ -1854,9 +1846,7 @@ def draggable(self, state=None, use_blit=False):
1854
1846
1855
1847
class Annotation (Text , _AnnotationBase ):
1856
1848
def __str__ (self ):
1857
- return "Annotation(%g,%g,%s)" % (self .xy [0 ],
1858
- self .xy [1 ],
1859
- repr (self ._text ))
1849
+ return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1860
1850
1861
1851
@docstring .dedent_interpd
1862
1852
def __init__ (self , s , xy ,
@@ -1875,10 +1865,10 @@ def __init__(self, s, xy,
1875
1865
----------
1876
1866
1877
1867
s : str
1878
- The text of the annotation
1868
+ The text of the annotation.
1879
1869
1880
1870
xy : iterable
1881
- Length 2 sequence specifying the *(x,y)* point to annotate
1871
+ Length 2 sequence specifying the *(x,y)* point to annotate.
1882
1872
1883
1873
xytext : iterable, optional
1884
1874
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2088,15 +2078,14 @@ def set_figure(self, fig):
2088
2078
Artist .set_figure (self , fig )
2089
2079
2090
2080
def update_positions (self , renderer ):
2091
- """"Update the pixel positions of the annotated point and the
2092
- text.
2081
+ """Update the pixel positions of the annotated point and the text.
2093
2082
"""
2094
2083
xy_pixel = self ._get_position_xy (renderer )
2095
2084
self ._update_position_xytext (renderer , xy_pixel )
2096
2085
2097
2086
def _update_position_xytext (self , renderer , xy_pixel ):
2098
- """Update the pixel positions of the annotation text and the arrow
2099
- patch.
2087
+ """
2088
+ Update the pixel positions of the annotation text and the arrow patch.
2100
2089
"""
2101
2090
# generate transformation,
2102
2091
self .set_transform (self ._get_xy_transform (renderer , self .anncoords ))
@@ -2235,7 +2224,6 @@ def get_window_extent(self, renderer=None):
2235
2224
simpler to call the method after saving the figure. The
2236
2225
*dpi* used defaults to self.figure.dpi; the renderer dpi is
2237
2226
irrelevant.
2238
-
2239
2227
'''
2240
2228
if not self .get_visible ():
2241
2229
return Bbox .unit ()
0 commit comments