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

Skip to content

Commit e770e8c

Browse files
committed
Various style fixes.
1 parent ad94c82 commit e770e8c

File tree

1 file changed

+37
-51
lines changed

1 file changed

+37
-51
lines changed

lib/matplotlib/text.py

Lines changed: 37 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,8 @@ 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+
"""Get the (possibly unit converted) transformed x, y in display coords
231+
"""
235232
x, y = self.get_unitless_position()
236233
return self.get_transform().transform_point((x, y))
237234

@@ -242,7 +239,7 @@ def _get_multialignment(self):
242239
return self._horizontalalignment
243240

244241
def get_rotation(self):
245-
'return the text angle as float in degrees'
242+
"""Return the text angle as float in degrees."""
246243
return get_rotation(self._rotation) # string_or_number -> number
247244

248245
def set_rotation_mode(self, m):
@@ -266,11 +263,11 @@ def set_rotation_mode(self, m):
266263
self.stale = True
267264

268265
def get_rotation_mode(self):
269-
"get text rotation mode"
266+
"""Get text rotation mode."""
270267
return self._rotation_mode
271268

272269
def update_from(self, other):
273-
'Copy properties from other to self'
270+
"""Copy properties from other to self."""
274271
Artist.update_from(self, other)
275272
self._color = other._color
276273
self._multialignment = other._multialignment
@@ -482,16 +479,16 @@ def set_bbox(self, rectprops):
482479

483480
def get_bbox_patch(self):
484481
"""
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.
487483
"""
488484
return self._bbox_patch
489485

490486
def update_bbox_position_size(self, renderer):
491487
"""
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.
495492
"""
496493

497494
if self._bbox_patch:
@@ -515,9 +512,8 @@ def update_bbox_position_size(self, renderer):
515512
self._bbox_patch.set_mutation_scale(fontsize_in_pixel)
516513

517514
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.
521517
"""
522518

523519
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
@@ -534,7 +530,6 @@ def _update_clip_properties(self):
534530
clipprops = dict(clip_box=self.clipbox,
535531
clip_path=self._clippath,
536532
clip_on=self._clipon)
537-
538533
if self._bbox_patch:
539534
bbox = self._bbox_patch.update(clipprops)
540535

@@ -584,13 +579,11 @@ def set_clip_on(self, b):
584579
self._update_clip_properties()
585580

586581
def get_wrap(self):
587-
"""
588-
Returns the wrapping state for the text.
589-
"""
582+
"""Return the wrapping state for the text."""
590583
return self._wrap
591584

592585
def set_wrap(self, wrap):
593-
"""Sets the wrapping state for the text.
586+
"""Set the wrapping state for the text.
594587
595588
..
596589
ACCEPTS: bool
@@ -603,8 +596,8 @@ def set_wrap(self, wrap):
603596

604597
def _get_wrap_line_width(self):
605598
"""
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.
608601
"""
609602
x0, y0 = self.get_transform().transform(self.get_position())
610603
figure_box = self.get_figure().get_window_extent()
@@ -616,10 +609,7 @@ def _get_wrap_line_width(self):
616609

617610
left = self._get_dist_to_box(rotation, x0, y0, figure_box)
618611
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)
623613

624614
if alignment == 'left':
625615
line_width = left
@@ -632,8 +622,8 @@ def _get_wrap_line_width(self):
632622

633623
def _get_dist_to_box(self, rotation, x0, y0, figure_box):
634624
"""
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.
637627
"""
638628
if rotation > 270:
639629
quad = rotation - 270
@@ -655,7 +645,7 @@ def _get_dist_to_box(self, rotation, x0, y0, figure_box):
655645

656646
def _get_rendered_text_width(self, text):
657647
"""
658-
Returns the width of a given text string, in pixels.
648+
Return the width of a given text string, in pixels.
659649
"""
660650
w, h, d = self._renderer.get_text_width_height_descent(
661651
text,
@@ -1306,7 +1296,7 @@ class TextWithDash(Text):
13061296
__name__ = 'textwithdash'
13071297

13081298
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)
13101300

13111301
def __init__(self,
13121302
x=0, y=0, text='',
@@ -1935,9 +1925,7 @@ def draggable(self, state=None, use_blit=False):
19351925

19361926
class Annotation(Text, _AnnotationBase):
19371927
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)
19411929

19421930
@docstring.dedent_interpd
19431931
def __init__(self, s, xy,
@@ -1956,10 +1944,10 @@ def __init__(self, s, xy,
19561944
----------
19571945
19581946
s : str
1959-
The text of the annotation
1947+
The text of the annotation.
19601948
19611949
xy : iterable
1962-
Length 2 sequence specifying the *(x,y)* point to annotate
1950+
Length 2 sequence specifying the *(x,y)* point to annotate.
19631951
19641952
xytext : iterable, optional
19651953
Length 2 sequence specifying the *(x,y)* to place the text
@@ -2177,15 +2165,14 @@ def set_figure(self, fig):
21772165
Artist.set_figure(self, fig)
21782166

21792167
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.
21822169
"""
21832170
xy_pixel = self._get_position_xy(renderer)
21842171
self._update_position_xytext(renderer, xy_pixel)
21852172

21862173
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.
21892176
"""
21902177
# generate transformation,
21912178
self.set_transform(self._get_xy_transform(renderer, self.anncoords))
@@ -2324,7 +2311,6 @@ def get_window_extent(self, renderer=None):
23242311
simpler to call the method after saving the figure. The
23252312
*dpi* used defaults to self.figure.dpi; the renderer dpi is
23262313
irrelevant.
2327-
23282314
'''
23292315
if not self.get_visible():
23302316
return Bbox.unit()

0 commit comments

Comments
 (0)