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

Skip to content

Commit c5b2b49

Browse files
authored
Merge pull request matplotlib#12764 from anntzer/rendererdocs
Cleanup Renderer/GraphicsContext docs.
2 parents 3c0c9db + 6de75f3 commit c5b2b49

File tree

10 files changed

+216
-265
lines changed

10 files changed

+216
-265
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 104 additions & 162 deletions
Large diffs are not rendered by default.

lib/matplotlib/backends/backend_agg.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def tostring_rgba_minimized(self):
118118
return np.array(region), extents
119119

120120
def draw_path(self, gc, path, transform, rgbFace=None):
121+
# docstring inherited
121122
nmax = rcParams['agg.path.chunksize'] # here at least for testing
122123
npts = path.vertices.shape[0]
123124

@@ -162,9 +163,8 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
162163
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)
163164

164165
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
165-
"""
166-
Render the text
167-
"""
166+
# docstring inherited
167+
168168
if ismath:
169169
return self.draw_mathtext(gc, x, y, s, prop, angle)
170170

@@ -192,11 +192,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
192192
font, np.round(x - xd + xo), np.round(y + yd + yo) + 1, angle, gc)
193193

194194
def get_text_width_height_descent(self, s, prop, ismath):
195-
"""
196-
Get the width, height, and descent (offset from the bottom
197-
to the baseline), in display coords, of the string *s* with
198-
:class:`~matplotlib.font_manager.FontProperties` *prop*
199-
"""
195+
# docstring inherited
196+
200197
if ismath in ["TeX", "TeX!"]:
201198
# todo: handle props
202199
size = prop.get_size_in_points()
@@ -222,6 +219,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
222219
return w, h, d
223220

224221
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
222+
# docstring inherited
225223
# todo, handle props, angle, origins
226224
size = prop.get_size_in_points()
227225

@@ -239,7 +237,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
239237
self._renderer.draw_text_image(Z, x, y, angle, gc)
240238

241239
def get_canvas_width_height(self):
242-
'return the canvas width and height in display coords'
240+
# docstring inherited
243241
return self.width, self.height
244242

245243
def _get_agg_font(self, prop):
@@ -256,10 +254,7 @@ def _get_agg_font(self, prop):
256254
return font
257255

258256
def points_to_pixels(self, points):
259-
"""
260-
convert point measures to pixes using dpi and the pixels per
261-
inch of the display
262-
"""
257+
# docstring inherited
263258
return points * self.dpi / 72
264259

265260
def tostring_rgb(self):
@@ -275,15 +270,15 @@ def clear(self):
275270
self._renderer.clear()
276271

277272
def option_image_nocomposite(self):
273+
# docstring inherited
274+
278275
# It is generally faster to composite each image directly to
279276
# the Figure, and there's no file size benefit to compositing
280277
# with the Agg backend
281278
return True
282279

283280
def option_scale_image(self):
284-
"""
285-
agg backend doesn't support arbitrary scaling of image.
286-
"""
281+
# docstring inherited
287282
return False
288283

289284
def restore_region(self, region, bbox=None, xy=None):

lib/matplotlib/backends/backend_cairo.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def convert_path(ctx, path, transform, clip=None):
225225
_append_path(ctx, path, transform, clip)
226226

227227
def draw_path(self, gc, path, transform, rgbFace=None):
228+
# docstring inherited
228229
ctx = gc.ctx
229230
# Clip the path to the actual rendering extents if it isn't filled.
230231
clip = (ctx.clip_extents()
@@ -239,8 +240,9 @@ def draw_path(self, gc, path, transform, rgbFace=None):
239240

240241
def draw_markers(self, gc, marker_path, marker_trans, path, transform,
241242
rgbFace=None):
242-
ctx = gc.ctx
243+
# docstring inherited
243244

245+
ctx = gc.ctx
244246
ctx.new_path()
245247
# Create the path for the marker; it needs to be flipped here already!
246248
_append_path(ctx, marker_path, marker_trans + Affine2D().scale(1, -1))
@@ -349,6 +351,8 @@ def draw_image(self, gc, x, y, im):
349351
ctx.restore()
350352

351353
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
354+
# docstring inherited
355+
352356
# Note: x,y are device/display coords, not user-coords, unlike other
353357
# draw_* methods
354358
if ismath:
@@ -404,9 +408,12 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
404408
ctx.restore()
405409

406410
def get_canvas_width_height(self):
411+
# docstring inherited
407412
return self.width, self.height
408413

409414
def get_text_width_height_descent(self, s, prop, ismath):
415+
# docstring inherited
416+
410417
if ismath:
411418
width, height, descent, fonts, used_characters = \
412419
self.mathtext_parser.parse(s, self.dpi, prop)
@@ -433,12 +440,14 @@ def get_text_width_height_descent(self, s, prop, ismath):
433440
return w, h, h + y_bearing
434441

435442
def new_gc(self):
443+
# docstring inherited
436444
self.gc.ctx.save()
437445
self.gc._alpha = 1
438446
self.gc._forced_alpha = False # if True, _alpha overrides A from RGBA
439447
return self.gc
440448

441449
def points_to_pixels(self, points):
450+
# docstring inherited
442451
return points / 72 * self.dpi
443452

444453

lib/matplotlib/backends/backend_pdf.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,7 @@ def check_gc(self, gc, fillcolor=None):
16261626
gc._effective_alphas = orig_alphas
16271627

16281628
def track_characters(self, font, s):
1629-
"""Keeps track of which characters are required from
1630-
each font."""
1629+
"""Keeps track of which characters are required from each font."""
16311630
if isinstance(font, str):
16321631
fname = font
16331632
else:
@@ -1647,19 +1646,16 @@ def get_image_magnification(self):
16471646
return self.image_dpi/72.0
16481647

16491648
def option_scale_image(self):
1650-
"""
1651-
pdf backend support arbitrary scaling of image.
1652-
"""
1649+
# docstring inherited
16531650
return True
16541651

16551652
def option_image_nocomposite(self):
1656-
"""
1657-
return whether to generate a composite image from multiple images on
1658-
a set of axes
1659-
"""
1653+
# docstring inherited
16601654
return not rcParams['image.composite_image']
16611655

16621656
def draw_image(self, gc, x, y, im, transform=None):
1657+
# docstring inherited
1658+
16631659
h, w = im.shape[:2]
16641660
if w == 0 or h == 0:
16651661
return
@@ -1688,6 +1684,7 @@ def draw_image(self, gc, x, y, im, transform=None):
16881684
imob, Op.use_xobject, Op.grestore)
16891685

16901686
def draw_path(self, gc, path, transform, rgbFace=None):
1687+
# docstring inherited
16911688
self.check_gc(gc, rgbFace)
16921689
self.file.writePath(
16931690
path, transform,
@@ -1767,6 +1764,8 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
17671764

17681765
def draw_markers(self, gc, marker_path, marker_trans, path, trans,
17691766
rgbFace=None):
1767+
# docstring inherited
1768+
17701769
# Same logic as in draw_path_collection
17711770
len_marker_path = len(marker_path)
17721771
uses = len(path)
@@ -1899,6 +1898,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
18991898
self.file.output(Op.grestore)
19001899

19011900
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
1901+
# docstring inherited
19021902
texmanager = self.get_texmanager()
19031903
fontsize = prop.get_size_in_points()
19041904
dvifile = texmanager.make_dvi(s, fontsize)
@@ -1982,6 +1982,8 @@ def encode_string(self, s, fonttype):
19821982
return s.encode('utf-16be', 'replace')
19831983

19841984
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
1985+
# docstring inherited
1986+
19851987
# TODO: combine consecutive texts into one BT/ET delimited section
19861988

19871989
# This function is rather complex, since there is no way to
@@ -2017,9 +2019,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
20172019
fonttype = 42
20182020

20192021
def check_simple_method(s):
2020-
"""Determine if we should use the simple or woven method
2021-
to output this text, and chunks the string into 1-byte and
2022-
2-byte sections if necessary."""
2022+
"""
2023+
Determine if we should use the simple or woven method to output
2024+
this text, and chunks the string into 1-byte and 2-byte sections if
2025+
necessary.
2026+
"""
20232027
use_simple_method = True
20242028
chunks = []
20252029

@@ -2052,9 +2056,10 @@ def draw_text_simple():
20522056
Op.end_text)
20532057

20542058
def draw_text_woven(chunks):
2055-
"""Outputs text using the woven method, alternating
2056-
between chunks of 1-byte characters and 2-byte characters.
2057-
Only used for Type 3 fonts."""
2059+
"""
2060+
Outputs text using the woven method, alternating between chunks of
2061+
1-byte and 2-byte characters. Only used for Type 3 fonts.
2062+
"""
20582063
chunks = [(a, ''.join(b)) for a, b in chunks]
20592064

20602065
# Do the rotation and global translation as a single matrix
@@ -2122,6 +2127,8 @@ def draw_text_woven(chunks):
21222127
return draw_text_woven(chunks)
21232128

21242129
def get_text_width_height_descent(self, s, prop, ismath):
2130+
# docstring inherited
2131+
21252132
if rcParams['text.usetex']:
21262133
texmanager = self.get_texmanager()
21272134
fontsize = prop.get_size_in_points()
@@ -2177,12 +2184,15 @@ def _get_font_ttf(self, prop):
21772184
return font
21782185

21792186
def flipy(self):
2187+
# docstring inherited
21802188
return False
21812189

21822190
def get_canvas_width_height(self):
2191+
# docstring inherited
21832192
return self.file.width * 72.0, self.file.height * 72.0
21842193

21852194
def new_gc(self):
2195+
# docstring inherited
21862196
return GraphicsContextPdf(self.file)
21872197

21882198

lib/matplotlib/backends/backend_pgf.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ def __init__(self, figure, fh, dummy=False):
406406

407407
def draw_markers(self, gc, marker_path, marker_trans, path, trans,
408408
rgbFace=None):
409+
# docstring inherited
410+
409411
writeln(self.fh, r"\begin{pgfscope}")
410412

411413
# convert from display units to in
@@ -437,6 +439,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
437439
writeln(self.fh, r"\end{pgfscope}")
438440

439441
def draw_path(self, gc, path, transform, rgbFace=None):
442+
# docstring inherited
440443
writeln(self.fh, r"\begin{pgfscope}")
441444
# draw the path
442445
self._print_pgf_clip(gc)
@@ -608,19 +611,16 @@ def _pgf_path_draw(self, stroke=True, fill=False):
608611
writeln(self.fh, r"\pgfusepath{%s}" % ",".join(actions))
609612

610613
def option_scale_image(self):
611-
"""
612-
pgf backend supports affine transform of image.
613-
"""
614+
# docstring inherited
614615
return True
615616

616617
def option_image_nocomposite(self):
617-
"""
618-
return whether to generate a composite image from multiple images on
619-
a set of axes
620-
"""
618+
# docstring inherited
621619
return not rcParams['image.composite_image']
622620

623621
def draw_image(self, gc, x, y, im, transform=None):
622+
# docstring inherited
623+
624624
h, w = im.shape[:2]
625625
if w == 0 or h == 0:
626626
return
@@ -655,9 +655,12 @@ def draw_image(self, gc, x, y, im, transform=None):
655655
writeln(self.fh, r"\end{pgfscope}")
656656

657657
def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!", mtext=None):
658+
# docstring inherited
658659
self.draw_text(gc, x, y, s, prop, angle, ismath, mtext)
659660

660661
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
662+
# docstring inherited
663+
661664
# prepare string for tex
662665
s = common_texification(s)
663666
prop_cmds = _font_properties_str(prop)
@@ -707,6 +710,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
707710
writeln(self.fh, r"\end{pgfscope}")
708711

709712
def get_text_width_height_descent(self, s, prop, ismath):
713+
# docstring inherited
714+
710715
# check if the math is supposed to be displaystyled
711716
s = common_texification(s)
712717

@@ -719,15 +724,19 @@ def get_text_width_height_descent(self, s, prop, ismath):
719724
return w * f, h * f, d * f
720725

721726
def flipy(self):
727+
# docstring inherited
722728
return False
723729

724730
def get_canvas_width_height(self):
731+
# docstring inherited
725732
return self.figure.get_figwidth(), self.figure.get_figheight()
726733

727734
def points_to_pixels(self, points):
735+
# docstring inherited
728736
return points * mpl_pt_to_in * self.dpi
729737

730738
def new_gc(self):
739+
# docstring inherited
731740
return GraphicsContextPgf()
732741

733742

0 commit comments

Comments
 (0)