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

Skip to content

Commit 4bba970

Browse files
committed
Various style fixes.
1 parent ad94c82 commit 4bba970

File tree

1 file changed

+38
-51
lines changed

1 file changed

+38
-51
lines changed

lib/matplotlib/text.py

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
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."""
4242

4343
if fontdict is not None:
4444
override.update(fontdict)
@@ -65,25 +65,22 @@ def _wrap_text(textobj):
6565
# Extracted from Text's method to serve as a function
6666
def get_rotation(rotation):
6767
"""
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.
7069
7170
*rotation* may be 'horizontal', 'vertical', or a numeric value in degrees.
7271
"""
7372
try:
74-
angle = float(rotation)
73+
return float(rotation) % 360
7574
except (ValueError, TypeError):
7675
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.
8180
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))
8784

8885

8986
def _get_textbox(text, renderer):
@@ -120,7 +117,6 @@ def _get_textbox(text, renderer):
120117
w_box, h_box = max(projected_xs) - xt_box, max(projected_ys) - yt_box
121118

122119
tr = mtransforms.Affine2D().rotate(theta)
123-
124120
x_box, y_box = tr.transform_point((xt_box, yt_box))
125121

126122
return x_box, y_box, w_box, h_box
@@ -231,7 +227,9 @@ def contains(self, mouseevent):
231227
return inside, cattr
232228

233229
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+
"""
235233
x, y = self.get_unitless_position()
236234
return self.get_transform().transform_point((x, y))
237235

@@ -242,7 +240,7 @@ def _get_multialignment(self):
242240
return self._horizontalalignment
243241

244242
def get_rotation(self):
245-
'return the text angle as float in degrees'
243+
"""Return the text angle as float in degrees."""
246244
return get_rotation(self._rotation) # string_or_number -> number
247245

248246
def set_rotation_mode(self, m):
@@ -266,11 +264,11 @@ def set_rotation_mode(self, m):
266264
self.stale = True
267265

268266
def get_rotation_mode(self):
269-
"get text rotation mode"
267+
"""Get text rotation mode."""
270268
return self._rotation_mode
271269

272270
def update_from(self, other):
273-
'Copy properties from other to self'
271+
"""Copy properties from other to self."""
274272
Artist.update_from(self, other)
275273
self._color = other._color
276274
self._multialignment = other._multialignment
@@ -482,16 +480,16 @@ def set_bbox(self, rectprops):
482480

483481
def get_bbox_patch(self):
484482
"""
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.
487484
"""
488485
return self._bbox_patch
489486

490487
def update_bbox_position_size(self, renderer):
491488
"""
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.
495493
"""
496494

497495
if self._bbox_patch:
@@ -515,9 +513,8 @@ def update_bbox_position_size(self, renderer):
515513
self._bbox_patch.set_mutation_scale(fontsize_in_pixel)
516514

517515
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.
521518
"""
522519

523520
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
@@ -534,7 +531,6 @@ def _update_clip_properties(self):
534531
clipprops = dict(clip_box=self.clipbox,
535532
clip_path=self._clippath,
536533
clip_on=self._clipon)
537-
538534
if self._bbox_patch:
539535
bbox = self._bbox_patch.update(clipprops)
540536

@@ -584,13 +580,11 @@ def set_clip_on(self, b):
584580
self._update_clip_properties()
585581

586582
def get_wrap(self):
587-
"""
588-
Returns the wrapping state for the text.
589-
"""
583+
"""Return the wrapping state for the text."""
590584
return self._wrap
591585

592586
def set_wrap(self, wrap):
593-
"""Sets the wrapping state for the text.
587+
"""Set the wrapping state for the text.
594588
595589
..
596590
ACCEPTS: bool
@@ -603,8 +597,8 @@ def set_wrap(self, wrap):
603597

604598
def _get_wrap_line_width(self):
605599
"""
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.
608602
"""
609603
x0, y0 = self.get_transform().transform(self.get_position())
610604
figure_box = self.get_figure().get_window_extent()
@@ -616,10 +610,7 @@ def _get_wrap_line_width(self):
616610

617611
left = self._get_dist_to_box(rotation, x0, y0, figure_box)
618612
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)
623614

624615
if alignment == 'left':
625616
line_width = left
@@ -632,8 +623,8 @@ def _get_wrap_line_width(self):
632623

633624
def _get_dist_to_box(self, rotation, x0, y0, figure_box):
634625
"""
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.
637628
"""
638629
if rotation > 270:
639630
quad = rotation - 270
@@ -655,7 +646,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
655646

656647
def _get_rendered_text_width(self, text):
657648
"""
658-
Returns the width of a given text string, in pixels.
649+
Return the width of a given text string, in pixels.
659650
"""
660651
w, h, d = self._renderer.get_text_width_height_descent(
661652
text,
@@ -1306,7 +1297,7 @@ class TextWithDash(Text):
13061297
__name__ = 'textwithdash'
13071298

13081299
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)
13101301

13111302
def __init__(self,
13121303
x=0, y=0, text='',
@@ -1935,9 +1926,7 @@ def draggable(self, state=None, use_blit=False):
19351926

19361927
class Annotation(Text, _AnnotationBase):
19371928
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)
19411930

19421931
@docstring.dedent_interpd
19431932
def __init__(self, s, xy,
@@ -1956,10 +1945,10 @@ def __init__(self, s, xy,
19561945
----------
19571946
19581947
s : str
1959-
The text of the annotation
1948+
The text of the annotation.
19601949
19611950
xy : iterable
1962-
Length 2 sequence specifying the *(x,y)* point to annotate
1951+
Length 2 sequence specifying the *(x,y)* point to annotate.
19631952
19641953
xytext : iterable, optional
19651954
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2177,15 +2166,14 @@ def set_figure(self, fig):
21772166
Artist.set_figure(self, fig)
21782167

21792168
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.
21822170
"""
21832171
xy_pixel = self._get_position_xy(renderer)
21842172
self._update_position_xytext(renderer, xy_pixel)
21852173

21862174
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.
21892177
"""
21902178
# generate transformation,
21912179
self.set_transform(self._get_xy_transform(renderer, self.anncoords))
@@ -2324,7 +2312,6 @@ def get_window_extent(self, renderer=None):
23242312
simpler to call the method after saving the figure. The
23252313
*dpi* used defaults to self.figure.dpi; the renderer dpi is
23262314
irrelevant.
2327-
23282315
'''
23292316
if not self.get_visible():
23302317
return Bbox.unit()

0 commit comments

Comments
 (0)