Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cleanup Renderer/GraphicsContext docs. #12764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 104 additions & 162 deletions 266 lib/matplotlib/backend_bases.py

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions 27 lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def tostring_rgba_minimized(self):
return np.array(region), extents

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

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

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Render the text
"""
# docstring inherited

if ismath:
return self.draw_mathtext(gc, x, y, s, prop, angle)

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

def get_text_width_height_descent(self, s, prop, ismath):
"""
Get the width, height, and descent (offset from the bottom
to the baseline), in display coords, of the string *s* with
:class:`~matplotlib.font_manager.FontProperties` *prop*
"""
# docstring inherited

if ismath in ["TeX", "TeX!"]:
# todo: handle props
size = prop.get_size_in_points()
Expand All @@ -222,6 +219,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
return w, h, d

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

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

def get_canvas_width_height(self):
'return the canvas width and height in display coords'
# docstring inherited
return self.width, self.height

def _get_agg_font(self, prop):
Expand All @@ -256,10 +254,7 @@ def _get_agg_font(self, prop):
return font

def points_to_pixels(self, points):
"""
convert point measures to pixes using dpi and the pixels per
inch of the display
"""
# docstring inherited
return points * self.dpi / 72

def tostring_rgb(self):
Expand All @@ -275,15 +270,15 @@ def clear(self):
self._renderer.clear()

def option_image_nocomposite(self):
# docstring inherited

# It is generally faster to composite each image directly to
# the Figure, and there's no file size benefit to compositing
# with the Agg backend
return True

def option_scale_image(self):
"""
agg backend doesn't support arbitrary scaling of image.
"""
# docstring inherited
return False

def restore_region(self, region, bbox=None, xy=None):
Expand Down
11 changes: 10 additions & 1 deletion 11 lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def convert_path(ctx, path, transform, clip=None):
_append_path(ctx, path, transform, clip)

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

def draw_markers(self, gc, marker_path, marker_trans, path, transform,
rgbFace=None):
ctx = gc.ctx
# docstring inherited

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

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# docstring inherited

# Note: x,y are device/display coords, not user-coords, unlike other
# draw_* methods
if ismath:
Expand Down Expand Up @@ -404,9 +408,12 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
ctx.restore()

def get_canvas_width_height(self):
# docstring inherited
return self.width, self.height

def get_text_width_height_descent(self, s, prop, ismath):
# docstring inherited

if ismath:
width, height, descent, fonts, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
Expand All @@ -433,12 +440,14 @@ def get_text_width_height_descent(self, s, prop, ismath):
return w, h, h + y_bearing

def new_gc(self):
# docstring inherited
self.gc.ctx.save()
self.gc._alpha = 1
self.gc._forced_alpha = False # if True, _alpha overrides A from RGBA
return self.gc

def points_to_pixels(self, points):
# docstring inherited
return points / 72 * self.dpi


Expand Down
40 changes: 25 additions & 15 deletions 40 lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,7 @@ def check_gc(self, gc, fillcolor=None):
gc._effective_alphas = orig_alphas

def track_characters(self, font, s):
"""Keeps track of which characters are required from
each font."""
"""Keeps track of which characters are required from each font."""
if isinstance(font, str):
fname = font
else:
Expand All @@ -1641,19 +1640,16 @@ def get_image_magnification(self):
return self.image_dpi/72.0

def option_scale_image(self):
"""
pdf backend support arbitrary scaling of image.
"""
# docstring inherited
return True

def option_image_nocomposite(self):
"""
return whether to generate a composite image from multiple images on
a set of axes
"""
# docstring inherited
return not rcParams['image.composite_image']

def draw_image(self, gc, x, y, im, transform=None):
# docstring inherited

h, w = im.shape[:2]
if w == 0 or h == 0:
return
Expand Down Expand Up @@ -1682,6 +1678,7 @@ def draw_image(self, gc, x, y, im, transform=None):
imob, Op.use_xobject, Op.grestore)

def draw_path(self, gc, path, transform, rgbFace=None):
# docstring inherited
self.check_gc(gc, rgbFace)
self.file.writePath(
path, transform,
Expand Down Expand Up @@ -1761,6 +1758,8 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,

def draw_markers(self, gc, marker_path, marker_trans, path, trans,
rgbFace=None):
# docstring inherited

# Same logic as in draw_path_collection
len_marker_path = len(marker_path)
uses = len(path)
Expand Down Expand Up @@ -1893,6 +1892,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
self.file.output(Op.grestore)

def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
# docstring inherited
texmanager = self.get_texmanager()
fontsize = prop.get_size_in_points()
dvifile = texmanager.make_dvi(s, fontsize)
Expand Down Expand Up @@ -1976,6 +1976,8 @@ def encode_string(self, s, fonttype):
return s.encode('utf-16be', 'replace')

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# docstring inherited

# TODO: combine consecutive texts into one BT/ET delimited section

# This function is rather complex, since there is no way to
Expand Down Expand Up @@ -2011,9 +2013,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
fonttype = 42

def check_simple_method(s):
"""Determine if we should use the simple or woven method
to output this text, and chunks the string into 1-byte and
2-byte sections if necessary."""
"""
Determine if we should use the simple or woven method to output
this text, and chunks the string into 1-byte and 2-byte sections if
necessary.
"""
use_simple_method = True
chunks = []

Expand Down Expand Up @@ -2046,9 +2050,10 @@ def draw_text_simple():
Op.end_text)

def draw_text_woven(chunks):
"""Outputs text using the woven method, alternating
between chunks of 1-byte characters and 2-byte characters.
Only used for Type 3 fonts."""
"""
Outputs text using the woven method, alternating between chunks of
1-byte and 2-byte characters. Only used for Type 3 fonts.
"""
chunks = [(a, ''.join(b)) for a, b in chunks]

# Do the rotation and global translation as a single matrix
Expand Down Expand Up @@ -2116,6 +2121,8 @@ def draw_text_woven(chunks):
return draw_text_woven(chunks)

def get_text_width_height_descent(self, s, prop, ismath):
# docstring inherited

if rcParams['text.usetex']:
texmanager = self.get_texmanager()
fontsize = prop.get_size_in_points()
Expand Down Expand Up @@ -2171,12 +2178,15 @@ def _get_font_ttf(self, prop):
return font

def flipy(self):
# docstring inherited
return False

def get_canvas_width_height(self):
# docstring inherited
return self.file.width * 72.0, self.file.height * 72.0

def new_gc(self):
# docstring inherited
return GraphicsContextPdf(self.file)


Expand Down
23 changes: 16 additions & 7 deletions 23 lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ def __init__(self, figure, fh, dummy=False):

def draw_markers(self, gc, marker_path, marker_trans, path, trans,
rgbFace=None):
# docstring inherited

writeln(self.fh, r"\begin{pgfscope}")

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

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

def option_scale_image(self):
"""
pgf backend supports affine transform of image.
"""
# docstring inherited
return True

def option_image_nocomposite(self):
"""
return whether to generate a composite image from multiple images on
a set of axes
"""
# docstring inherited
return not rcParams['image.composite_image']

def draw_image(self, gc, x, y, im, transform=None):
# docstring inherited

h, w = im.shape[:2]
if w == 0 or h == 0:
return
Expand Down Expand Up @@ -655,9 +655,12 @@ def draw_image(self, gc, x, y, im, transform=None):
writeln(self.fh, r"\end{pgfscope}")

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

def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# docstring inherited

# prepare string for tex
s = common_texification(s)
prop_cmds = _font_properties_str(prop)
Expand Down Expand Up @@ -707,6 +710,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
writeln(self.fh, r"\end{pgfscope}")

def get_text_width_height_descent(self, s, prop, ismath):
# docstring inherited

# check if the math is supposed to be displaystyled
s = common_texification(s)

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

def flipy(self):
# docstring inherited
return False

def get_canvas_width_height(self):
# docstring inherited
return self.figure.get_figwidth(), self.figure.get_figheight()

def points_to_pixels(self, points):
# docstring inherited
return points * mpl_pt_to_in * self.dpi

def new_gc(self):
# docstring inherited
return GraphicsContextPgf()


Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.