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
- angle = 0.
62
+ return 0.
64
63
elif cbook ._str_equal (rotation , 'vertical' ):
65
- angle = 90.
64
+ return 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
@@ -125,9 +120,8 @@ def _get_textbox(text, renderer):
125
120
"weight" : ["fontweight" ],
126
121
})
127
122
class Text (Artist ):
128
- """
129
- Handle storing and drawing of text in window or data coordinates.
130
- """
123
+ """Handle storing and drawing of text in window or data coordinates."""
124
+
131
125
zorder = 3
132
126
_cached = cbook .maxdict (50 )
133
127
@@ -149,8 +143,7 @@ def __init__(self,
149
143
** kwargs
150
144
):
151
145
"""
152
- Create a :class:`~matplotlib.text.Text` instance at *x*, *y*
153
- with string *text*.
146
+ Create a `Text` instance at *x*, *y* with string *text*.
154
147
155
148
Valid kwargs are
156
149
%(Text)s
@@ -232,7 +225,9 @@ def contains(self, mouseevent):
232
225
return inside , cattr
233
226
234
227
def _get_xy_display (self ):
235
- '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
+ """
236
231
x , y = self .get_unitless_position ()
237
232
return self .get_transform ().transform_point ((x , y ))
238
233
@@ -243,7 +238,7 @@ def _get_multialignment(self):
243
238
return self ._horizontalalignment
244
239
245
240
def get_rotation (self ):
246
- 'return the text angle as float in degrees'
241
+ """Return the text angle as float in degrees."""
247
242
return get_rotation (self ._rotation ) # string_or_number -> number
248
243
249
244
def set_rotation_mode (self , m ):
@@ -266,11 +261,11 @@ def set_rotation_mode(self, m):
266
261
self .stale = True
267
262
268
263
def get_rotation_mode (self ):
269
- "get text rotation mode"
264
+ """Get the text rotation mode."" "
270
265
return self ._rotation_mode
271
266
272
267
def update_from (self , other ):
273
- ' Copy properties from other to self'
268
+ """ Copy properties from other to self."""
274
269
Artist .update_from (self , other )
275
270
self ._color = other ._color
276
271
self ._multialignment = other ._multialignment
@@ -481,16 +476,16 @@ def set_bbox(self, rectprops):
481
476
482
477
def get_bbox_patch (self ):
483
478
"""
484
- Return the bbox Patch object. Returns None if the
485
- FancyBboxPatch is not made.
479
+ Return the bbox Patch, or None if the FancyBboxPatch is not made.
486
480
"""
487
481
return self ._bbox_patch
488
482
489
483
def update_bbox_position_size (self , renderer ):
490
484
"""
491
- Update the location and the size of the bbox. This method
492
- should be used when the position and size of the bbox needs to
493
- 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.
494
489
"""
495
490
496
491
if self ._bbox_patch :
@@ -514,9 +509,8 @@ def update_bbox_position_size(self, renderer):
514
509
self ._bbox_patch .set_mutation_scale (fontsize_in_pixel )
515
510
516
511
def _draw_bbox (self , renderer , posx , posy ):
517
-
518
- """ Update the location and the size of the bbox
519
- (FancyBboxPatch), and draw
512
+ """
513
+ Update the location and size of the bbox (FancyBboxPatch), and draw.
520
514
"""
521
515
522
516
x_box , y_box , w_box , h_box = _get_textbox (self , renderer )
@@ -533,7 +527,6 @@ def _update_clip_properties(self):
533
527
clipprops = dict (clip_box = self .clipbox ,
534
528
clip_path = self ._clippath ,
535
529
clip_on = self ._clipon )
536
-
537
530
if self ._bbox_patch :
538
531
bbox = self ._bbox_patch .update (clipprops )
539
532
@@ -586,11 +579,11 @@ def set_clip_on(self, b):
586
579
self ._update_clip_properties ()
587
580
588
581
def get_wrap (self ):
589
- """Returns the wrapping state for the text."""
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
Parameters
596
589
----------
@@ -601,8 +594,8 @@ def set_wrap(self, wrap):
601
594
602
595
def _get_wrap_line_width (self ):
603
596
"""
604
- Returns the maximum line width for wrapping text based on the
605
- current orientation.
597
+ Return the maximum line width for wrapping text based on the current
598
+ orientation.
606
599
"""
607
600
x0 , y0 = self .get_transform ().transform (self .get_position ())
608
601
figure_box = self .get_figure ().get_window_extent ()
@@ -614,10 +607,7 @@ def _get_wrap_line_width(self):
614
607
615
608
left = self ._get_dist_to_box (rotation , x0 , y0 , figure_box )
616
609
right = self ._get_dist_to_box (
617
- (180 + rotation ) % 360 ,
618
- x0 ,
619
- y0 ,
620
- figure_box )
610
+ (180 + rotation ) % 360 , x0 , y0 , figure_box )
621
611
622
612
if alignment == 'left' :
623
613
line_width = left
@@ -630,8 +620,8 @@ def _get_wrap_line_width(self):
630
620
631
621
def _get_dist_to_box (self , rotation , x0 , y0 , figure_box ):
632
622
"""
633
- Returns the distance from the given points, to the boundaries
634
- of a rotated box in pixels.
623
+ Return the distance from the given points to the boundaries of a
624
+ rotated box, in pixels.
635
625
"""
636
626
if rotation > 270 :
637
627
quad = rotation - 270
@@ -653,7 +643,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
653
643
654
644
def _get_rendered_text_width (self , text ):
655
645
"""
656
- Returns the width of a given text string, in pixels.
646
+ Return the width of a given text string, in pixels.
657
647
"""
658
648
w , h , d = self ._renderer .get_text_width_height_descent (
659
649
text ,
@@ -1228,7 +1218,7 @@ class TextWithDash(Text):
1228
1218
__name__ = 'textwithdash'
1229
1219
1230
1220
def __str__ (self ):
1231
- return "TextWithDash(%g,%g,%s )" % (self ._x , self ._y , repr ( self ._text ) )
1221
+ return "TextWithDash(%g, %g, %r )" % (self ._x , self ._y , self ._text )
1232
1222
1233
1223
def __init__ (self ,
1234
1224
x = 0 , y = 0 , text = '' ,
@@ -1855,9 +1845,7 @@ def draggable(self, state=None, use_blit=False):
1855
1845
1856
1846
class Annotation (Text , _AnnotationBase ):
1857
1847
def __str__ (self ):
1858
- return "Annotation(%g,%g,%s)" % (self .xy [0 ],
1859
- self .xy [1 ],
1860
- repr (self ._text ))
1848
+ return "Annotation(%g, %g, %r)" % (self .xy [0 ], self .xy [1 ], self ._text )
1861
1849
1862
1850
@docstring .dedent_interpd
1863
1851
def __init__ (self , s , xy ,
@@ -1876,10 +1864,10 @@ def __init__(self, s, xy,
1876
1864
----------
1877
1865
1878
1866
s : str
1879
- The text of the annotation
1867
+ The text of the annotation.
1880
1868
1881
1869
xy : iterable
1882
- Length 2 sequence specifying the *(x,y)* point to annotate
1870
+ Length 2 sequence specifying the *(x,y)* point to annotate.
1883
1871
1884
1872
xytext : iterable, optional
1885
1873
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2089,15 +2077,13 @@ def set_figure(self, fig):
2089
2077
Artist .set_figure (self , fig )
2090
2078
2091
2079
def update_positions (self , renderer ):
2092
- """"Update the pixel positions of the annotated point and the
2093
- text.
2094
- """
2080
+ """Update the pixel positions of the annotated point and the text."""
2095
2081
xy_pixel = self ._get_position_xy (renderer )
2096
2082
self ._update_position_xytext (renderer , xy_pixel )
2097
2083
2098
2084
def _update_position_xytext (self , renderer , xy_pixel ):
2099
- """Update the pixel positions of the annotation text and the arrow
2100
- patch.
2085
+ """
2086
+ Update the pixel positions of the annotation text and the arrow patch.
2101
2087
"""
2102
2088
# generate transformation,
2103
2089
self .set_transform (self ._get_xy_transform (renderer , self .anncoords ))
@@ -2236,7 +2222,6 @@ def get_window_extent(self, renderer=None):
2236
2222
simpler to call the method after saving the figure. The
2237
2223
*dpi* used defaults to self.figure.dpi; the renderer dpi is
2238
2224
irrelevant.
2239
-
2240
2225
'''
2241
2226
if not self .get_visible ():
2242
2227
return Bbox .unit ()
0 commit comments