Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 942d105

Browse files
committed
Various style fixes.
1 parent 3797bd8 commit 942d105

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

lib/matplotlib/text.py

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
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."""
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
5252
def 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:
6362
angle = 0.
6463
elif cbook._str_equal(rotation, 'vertical'):
6564
angle = 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

7471
def _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 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,
@@ -1227,7 +1219,7 @@ class TextWithDash(Text):
12271219
__name__ = 'textwithdash'
12281220

12291221
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)
12311223

12321224
def __init__(self,
12331225
x=0, y=0, text='',
@@ -1854,9 +1846,7 @@ def draggable(self, state=None, use_blit=False):
18541846

18551847
class Annotation(Text, _AnnotationBase):
18561848
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)
18601850

18611851
@docstring.dedent_interpd
18621852
def __init__(self, s, xy,
@@ -1875,10 +1865,10 @@ def __init__(self, s, xy,
18751865
----------
18761866
18771867
s : str
1878-
The text of the annotation
1868+
The text of the annotation.
18791869
18801870
xy : iterable
1881-
Length 2 sequence specifying the *(x,y)* point to annotate
1871+
Length 2 sequence specifying the *(x,y)* point to annotate.
18821872
18831873
xytext : iterable, optional
18841874
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2088,15 +2078,14 @@ def set_figure(self, fig):
20882078
Artist.set_figure(self, fig)
20892079

20902080
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.
20932082
"""
20942083
xy_pixel = self._get_position_xy(renderer)
20952084
self._update_position_xytext(renderer, xy_pixel)
20962085

20972086
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.
21002089
"""
21012090
# generate transformation,
21022091
self.set_transform(self._get_xy_transform(renderer, self.anncoords))
@@ -2235,7 +2224,6 @@ def get_window_extent(self, renderer=None):
22352224
simpler to call the method after saving the figure. The
22362225
*dpi* used defaults to self.figure.dpi; the renderer dpi is
22372226
irrelevant.
2238-
22392227
'''
22402228
if not self.get_visible():
22412229
return Bbox.unit()

0 commit comments

Comments
 (0)