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,8 @@ 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
+ """Get the (possibly unit converted) transformed x, y in display coords
231
+ """
235
232
x , y = self .get_unitless_position ()
236
233
return self .get_transform ().transform_point ((x , y ))
237
234
@@ -242,7 +239,7 @@ def _get_multialignment(self):
242
239
return self ._horizontalalignment
243
240
244
241
def get_rotation (self ):
245
- 'return the text angle as float in degrees'
242
+ """Return the text angle as float in degrees."""
246
243
return get_rotation (self ._rotation ) # string_or_number -> number
247
244
248
245
def set_rotation_mode (self , m ):
@@ -266,11 +263,11 @@ def set_rotation_mode(self, m):
266
263
self .stale = True
267
264
268
265
def get_rotation_mode (self ):
269
- "get text rotation mode"
266
+ """Get text rotation mode."" "
270
267
return self ._rotation_mode
271
268
272
269
def update_from (self , other ):
273
- ' Copy properties from other to self'
270
+ """ Copy properties from other to self."""
274
271
Artist .update_from (self , other )
275
272
self ._color = other ._color
276
273
self ._multialignment = other ._multialignment
@@ -482,16 +479,16 @@ def set_bbox(self, rectprops):
482
479
483
480
def get_bbox_patch (self ):
484
481
"""
485
- Return the bbox Patch object. Returns None if the
486
- FancyBboxPatch is not made.
482
+ Return the bbox Patch, or None if the FancyBboxPatch is not made.
487
483
"""
488
484
return self ._bbox_patch
489
485
490
486
def update_bbox_position_size (self , renderer ):
491
487
"""
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.
488
+ Update the location and the size of the bbox.
489
+
490
+ This method should be used when the position and size of the bbox needs
491
+ to be updated before actually drawing the bbox.
495
492
"""
496
493
497
494
if self ._bbox_patch :
@@ -515,9 +512,8 @@ def update_bbox_position_size(self, renderer):
515
512
self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
516
513
517
514
def _draw_bbox (self , renderer , posx , posy ):
518
-
519
- """ Update the location and the size of the bbox
520
- (FancyBboxPatch), and draw
515
+ """
516
+ Update the location and size of the bbox (FancyBboxPatch), and draw.
521
517
"""
522
518
523
519
x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
@@ -534,7 +530,6 @@ def _update_clip_properties(self):
534
530
clipprops = dict (clip_box = self .clipbox ,
535
531
clip_path = self ._clippath ,
536
532
clip_on = self ._clipon )
537
-
538
533
if self ._bbox_patch :
539
534
bbox = self ._bbox_patch .update (clipprops )
540
535
@@ -584,13 +579,11 @@ def set_clip_on(self, b):
584
579
self ._update_clip_properties ()
585
580
586
581
def get_wrap (self ):
587
- """
588
- Returns the wrapping state for the text.
589
- """
582
+ """Return the wrapping state for the text."""
590
583
return self ._wrap
591
584
592
585
def set_wrap (self , wrap ):
593
- """Sets the wrapping state for the text.
586
+ """Set the wrapping state for the text.
594
587
595
588
..
596
589
ACCEPTS: bool
@@ -603,8 +596,8 @@ def set_wrap(self, wrap):
603
596
604
597
def _get_wrap_line_width (self ):
605
598
"""
606
- Returns the maximum line width for wrapping text based on the
607
- current orientation.
599
+ Return the maximum line width for wrapping text based on the current
600
+ orientation.
608
601
"""
609
602
x0 , y0 = self .get_transform ().transform (self .get_position ())
610
603
figure_box = self .get_figure ().get_window_extent ()
@@ -616,10 +609,7 @@ def _get_wrap_line_width(self):
616
609
617
610
left = self ._get_dist_to_box (rotation , x0 , y0 , figure_box )
618
611
right = self ._get_dist_to_box (
619
- (180 + rotation ) % 360 ,
620
- x0 ,
621
- y0 ,
622
- figure_box )
612
+ (180 + rotation ) % 360 , x0 , y0 , figure_box )
623
613
624
614
if alignment == 'left' :
625
615
line_width = left
@@ -632,8 +622,8 @@ def _get_wrap_line_width(self):
632
622
633
623
def _get_dist_to_box (self , rotation , x0 , y0 , figure_box ):
634
624
"""
635
- Returns the distance from the given points, to the boundaries
636
- of a rotated box in pixels.
625
+ Return the distance from the given points to the boundaries of a
626
+ rotated box, in pixels.
637
627
"""
638
628
if rotation > 270 :
639
629
quad = rotation - 270
@@ -655,7 +645,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
655
645
656
646
def _get_rendered_text_width (self , text ):
657
647
"""
658
- Returns the width of a given text string, in pixels.
648
+ Return the width of a given text string, in pixels.
659
649
"""
660
650
w , h , d = self ._renderer .get_text_width_height_descent (
661
651
text ,
@@ -1306,7 +1296,7 @@ class TextWithDash(Text):
1306
1296
__name__ = 'textwithdash'
1307
1297
1308
1298
def __str__ (self ):
1309
- return "TextWithDash(%g,%g,%s )" % (self ._x , self ._y , repr ( self ._text ) )
1299
+ return "TextWithDash(%g, %g, %r )" % (self ._x , self ._y , self ._text )
1310
1300
1311
1301
def __init__ (self ,
1312
1302
x = 0 , y = 0 , text = '' ,
@@ -1935,9 +1925,7 @@ def draggable(self, state=None, use_blit=False):
1935
1925
1936
1926
class Annotation (Text , _AnnotationBase ):
1937
1927
def __str__ (self ):
1938
- return "Annotation(%g,%g,%s)" % (self .xy [0 ],
1939
- self .xy [1 ],
1940
- repr (self ._text ))
1928
+ return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1941
1929
1942
1930
@docstring .dedent_interpd
1943
1931
def __init__ (self , s , xy ,
@@ -1956,10 +1944,10 @@ def __init__(self, s, xy,
1956
1944
----------
1957
1945
1958
1946
s : str
1959
- The text of the annotation
1947
+ The text of the annotation.
1960
1948
1961
1949
xy : iterable
1962
- Length 2 sequence specifying the *(x,y)* point to annotate
1950
+ Length 2 sequence specifying the *(x,y)* point to annotate.
1963
1951
1964
1952
xytext : iterable, optional
1965
1953
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2177,15 +2165,14 @@ def set_figure(self, fig):
2177
2165
Artist .set_figure (self , fig )
2178
2166
2179
2167
def update_positions (self , renderer ):
2180
- """"Update the pixel positions of the annotated point and the
2181
- text.
2168
+ """Update the pixel positions of the annotated point and the text.
2182
2169
"""
2183
2170
xy_pixel = self ._get_position_xy (renderer )
2184
2171
self ._update_position_xytext (renderer , xy_pixel )
2185
2172
2186
2173
def _update_position_xytext (self , renderer , xy_pixel ):
2187
- """Update the pixel positions of the annotation text and the arrow
2188
- patch.
2174
+ """
2175
+ Update the pixel positions of the annotation text and the arrow patch.
2189
2176
"""
2190
2177
# generate transformation,
2191
2178
self .set_transform (self ._get_xy_transform (renderer , self .anncoords ))
@@ -2324,7 +2311,6 @@ def get_window_extent(self, renderer=None):
2324
2311
simpler to call the method after saving the figure. The
2325
2312
*dpi* used defaults to self.figure.dpi; the renderer dpi is
2326
2313
irrelevant.
2327
-
2328
2314
'''
2329
2315
if not self .get_visible ():
2330
2316
return Bbox .unit ()
0 commit comments