38
38
39
39
40
40
def _process_text_args (override , fontdict = None , ** kwargs ):
41
- "Return an override dict. See :func: `~pyplot.text' docstring for info"
41
+ """ Return an override dict. See `~pyplot.text' docstring for info."" "
42
42
43
43
if fontdict is not None :
44
44
override .update (fontdict )
@@ -65,25 +65,22 @@ def _wrap_text(textobj):
65
65
# Extracted from Text's method to serve as a function
66
66
def get_rotation (rotation ):
67
67
"""
68
- Return the text angle as float. The returned
69
- angle is between 0 and 360 deg.
68
+ Return the text angle as float between 0 and 360 degrees.
70
69
71
70
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
72
71
"""
73
72
try :
74
- angle = float (rotation )
73
+ return float (rotation ) % 360
75
74
except (ValueError , TypeError ):
76
75
isString = isinstance (rotation , six .string_types )
77
- if (( isString and rotation == 'horizontal' ) or rotation is None ) :
78
- angle = 0.
79
- elif ( isString and rotation == 'vertical' ) :
80
- angle = 90.
76
+ if (isString and rotation == 'horizontal' ) or rotation is None :
77
+ return 0.
78
+ elif isString and rotation == 'vertical' :
79
+ return 90.
81
80
else :
82
- raise ValueError ("rotation is {0} expected either 'horizontal'"
83
- " 'vertical', numeric value or"
84
- "None" .format (rotation ))
85
-
86
- return angle % 360
81
+ raise ValueError ("rotation is {!r}; expected either 'horizontal', "
82
+ "'vertical', numeric value, or None"
83
+ .format (rotation ))
87
84
88
85
89
86
def _get_textbox (text , renderer ):
@@ -120,7 +117,6 @@ def _get_textbox(text, renderer):
120
117
w_box , h_box = max (projected_xs ) - xt_box , max (projected_ys ) - yt_box
121
118
122
119
tr = mtransforms .Affine2D ().rotate (theta )
123
-
124
120
x_box , y_box = tr .transform_point ((xt_box , yt_box ))
125
121
126
122
return x_box , y_box , w_box , h_box
@@ -231,7 +227,9 @@ def contains(self, mouseevent):
231
227
return inside , cattr
232
228
233
229
def _get_xy_display (self ):
234
- 'get the (possibly unit converted) transformed x, y in display coords'
230
+ """
231
+ Get the (possibly unit converted) transformed x, y in display coords.
232
+ """
235
233
x , y = self .get_unitless_position ()
236
234
return self .get_transform ().transform_point ((x , y ))
237
235
@@ -242,7 +240,7 @@ def _get_multialignment(self):
242
240
return self ._horizontalalignment
243
241
244
242
def get_rotation (self ):
245
- 'return the text angle as float in degrees'
243
+ """Return the text angle as float in degrees."""
246
244
return get_rotation (self ._rotation ) # string_or_number -> number
247
245
248
246
def set_rotation_mode (self , m ):
@@ -266,11 +264,11 @@ def set_rotation_mode(self, m):
266
264
self .stale = True
267
265
268
266
def get_rotation_mode (self ):
269
- "get text rotation mode"
267
+ """Get text rotation mode."" "
270
268
return self ._rotation_mode
271
269
272
270
def update_from (self , other ):
273
- ' Copy properties from other to self'
271
+ """ Copy properties from other to self."""
274
272
Artist .update_from (self , other )
275
273
self ._color = other ._color
276
274
self ._multialignment = other ._multialignment
@@ -482,16 +480,16 @@ def set_bbox(self, rectprops):
482
480
483
481
def get_bbox_patch (self ):
484
482
"""
485
- Return the bbox Patch object. Returns None if the
486
- FancyBboxPatch is not made.
483
+ Return the bbox Patch, or None if the FancyBboxPatch is not made.
487
484
"""
488
485
return self ._bbox_patch
489
486
490
487
def update_bbox_position_size (self , renderer ):
491
488
"""
492
- Update the location and the size of the bbox. This method
493
- should be used when the position and size of the bbox needs to
494
- be updated before actually drawing the bbox.
489
+ Update the location and the size of the bbox.
490
+
491
+ This method should be used when the position and size of the bbox needs
492
+ to be updated before actually drawing the bbox.
495
493
"""
496
494
497
495
if self ._bbox_patch :
@@ -515,9 +513,8 @@ def update_bbox_position_size(self, renderer):
515
513
self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
516
514
517
515
def _draw_bbox (self , renderer , posx , posy ):
518
-
519
- """ Update the location and the size of the bbox
520
- (FancyBboxPatch), and draw
516
+ """
517
+ Update the location and size of the bbox (FancyBboxPatch), and draw.
521
518
"""
522
519
523
520
x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
@@ -534,7 +531,6 @@ def _update_clip_properties(self):
534
531
clipprops = dict (clip_box = self .clipbox ,
535
532
clip_path = self ._clippath ,
536
533
clip_on = self ._clipon )
537
-
538
534
if self ._bbox_patch :
539
535
bbox = self ._bbox_patch .update (clipprops )
540
536
@@ -584,13 +580,11 @@ def set_clip_on(self, b):
584
580
self ._update_clip_properties ()
585
581
586
582
def get_wrap (self ):
587
- """
588
- Returns the wrapping state for the text.
589
- """
583
+ """Return the wrapping state for the text."""
590
584
return self ._wrap
591
585
592
586
def set_wrap (self , wrap ):
593
- """Sets the wrapping state for the text.
587
+ """Set the wrapping state for the text.
594
588
595
589
..
596
590
ACCEPTS: bool
@@ -603,8 +597,8 @@ def set_wrap(self, wrap):
603
597
604
598
def _get_wrap_line_width (self ):
605
599
"""
606
- Returns the maximum line width for wrapping text based on the
607
- current orientation.
600
+ Return the maximum line width for wrapping text based on the current
601
+ orientation.
608
602
"""
609
603
x0 , y0 = self .get_transform ().transform (self .get_position ())
610
604
figure_box = self .get_figure ().get_window_extent ()
@@ -616,10 +610,7 @@ def _get_wrap_line_width(self):
616
610
617
611
left = self ._get_dist_to_box (rotation , x0 , y0 , figure_box )
618
612
right = self ._get_dist_to_box (
619
- (180 + rotation ) % 360 ,
620
- x0 ,
621
- y0 ,
622
- figure_box )
613
+ (180 + rotation ) % 360 , x0 , y0 , figure_box )
623
614
624
615
if alignment == 'left' :
625
616
line_width = left
@@ -632,8 +623,8 @@ def _get_wrap_line_width(self):
632
623
633
624
def _get_dist_to_box (self , rotation , x0 , y0 , figure_box ):
634
625
"""
635
- Returns the distance from the given points, to the boundaries
636
- of a rotated box in pixels.
626
+ Return the distance from the given points to the boundaries of a
627
+ rotated box, in pixels.
637
628
"""
638
629
if rotation > 270 :
639
630
quad = rotation - 270
@@ -655,7 +646,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
655
646
656
647
def _get_rendered_text_width (self , text ):
657
648
"""
658
- Returns the width of a given text string, in pixels.
649
+ Return the width of a given text string, in pixels.
659
650
"""
660
651
w , h , d = self ._renderer .get_text_width_height_descent (
661
652
text ,
@@ -1306,7 +1297,7 @@ class TextWithDash(Text):
1306
1297
__name__ = 'textwithdash'
1307
1298
1308
1299
def __str__ (self ):
1309
- return "TextWithDash(%g,%g,%s )" % (self ._x , self ._y , repr ( self ._text ) )
1300
+ return "TextWithDash(%g, %g, %r )" % (self ._x , self ._y , self ._text )
1310
1301
1311
1302
def __init__ (self ,
1312
1303
x = 0 , y = 0 , text = '' ,
@@ -1935,9 +1926,7 @@ def draggable(self, state=None, use_blit=False):
1935
1926
1936
1927
class Annotation (Text , _AnnotationBase ):
1937
1928
def __str__ (self ):
1938
- return "Annotation(%g,%g,%s)" % (self .xy [0 ],
1939
- self .xy [1 ],
1940
- repr (self ._text ))
1929
+ return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1941
1930
1942
1931
@docstring .dedent_interpd
1943
1932
def __init__ (self , s , xy ,
@@ -1956,10 +1945,10 @@ def __init__(self, s, xy,
1956
1945
----------
1957
1946
1958
1947
s : str
1959
- The text of the annotation
1948
+ The text of the annotation.
1960
1949
1961
1950
xy : iterable
1962
- Length 2 sequence specifying the *(x,y)* point to annotate
1951
+ Length 2 sequence specifying the *(x,y)* point to annotate.
1963
1952
1964
1953
xytext : iterable, optional
1965
1954
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2177,15 +2166,14 @@ def set_figure(self, fig):
2177
2166
Artist .set_figure (self , fig )
2178
2167
2179
2168
def update_positions (self , renderer ):
2180
- """"Update the pixel positions of the annotated point and the
2181
- text.
2169
+ """Update the pixel positions of the annotated point and the text.
2182
2170
"""
2183
2171
xy_pixel = self ._get_position_xy (renderer )
2184
2172
self ._update_position_xytext (renderer , xy_pixel )
2185
2173
2186
2174
def _update_position_xytext (self , renderer , xy_pixel ):
2187
- """Update the pixel positions of the annotation text and the arrow
2188
- patch.
2175
+ """
2176
+ Update the pixel positions of the annotation text and the arrow patch.
2189
2177
"""
2190
2178
# generate transformation,
2191
2179
self .set_transform (self ._get_xy_transform (renderer , self .anncoords ))
@@ -2324,7 +2312,6 @@ def get_window_extent(self, renderer=None):
2324
2312
simpler to call the method after saving the figure. The
2325
2313
*dpi* used defaults to self.figure.dpi; the renderer dpi is
2326
2314
irrelevant.
2327
-
2328
2315
'''
2329
2316
if not self .get_visible ():
2330
2317
return Bbox .unit ()
0 commit comments