MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _print_pgf_path

Method _print_pgf_path

lib/matplotlib/backends/backend_pgf.py:559–623  ·  view source on GitHub ↗
(self, gc, path, transform, rgbFace=None)

Source from the content-addressed store, hash-verified

557 dash_offset))
558
559 def _print_pgf_path(self, gc, path, transform, rgbFace=None):
560 f = 1. / self.dpi
561 # check for clip box / ignore clip for filled paths
562 bbox = gc.get_clip_rectangle() if gc else None
563 maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX.
564 if bbox and (rgbFace is None):
565 p1, p2 = bbox.get_points()
566 clip = (max(p1[0], -maxcoord), max(p1[1], -maxcoord),
567 min(p2[0], maxcoord), min(p2[1], maxcoord))
568 else:
569 clip = (-maxcoord, -maxcoord, maxcoord, maxcoord)
570 # build path
571 for points, code in path.iter_segments(transform, clip=clip):
572 if code == Path.MOVETO:
573 x, y = tuple(points)
574 _writeln(self.fh,
575 r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
576 (f * x, f * y))
577 elif code == Path.CLOSEPOLY:
578 _writeln(self.fh, r"\pgfpathclose")
579 elif code == Path.LINETO:
580 x, y = tuple(points)
581 _writeln(self.fh,
582 r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" %
583 (f * x, f * y))
584 elif code == Path.CURVE3:
585 cx, cy, px, py = tuple(points)
586 coords = cx * f, cy * f, px * f, py * f
587 _writeln(self.fh,
588 r"\pgfpathquadraticcurveto"
589 r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}"
590 % coords)
591 elif code == Path.CURVE4:
592 c1x, c1y, c2x, c2y, px, py = tuple(points)
593 coords = c1x * f, c1y * f, c2x * f, c2y * f, px * f, py * f
594 _writeln(self.fh,
595 r"\pgfpathcurveto"
596 r"{\pgfqpoint{%fin}{%fin}}"
597 r"{\pgfqpoint{%fin}{%fin}}"
598 r"{\pgfqpoint{%fin}{%fin}}"
599 % coords)
600
601 # apply pgf decorators
602 sketch_params = gc.get_sketch_params() if gc else None
603 if sketch_params is not None:
604 # Only "length" directly maps to "segment length" in PGF's API.
605 # PGF uses "amplitude" to pass the combined deviation in both x-
606 # and y-direction, while matplotlib only varies the length of the
607 # wiggle along the line ("randomness" and "length" parameters)
608 # and has a separate "scale" argument for the amplitude.
609 # -> Use "randomness" as PRNG seed to allow the user to force the
610 # same shape on multiple sketched lines
611 scale, length, randomness = sketch_params
612 if scale is not None:
613 # make matplotlib and PGF rendering visually similar
614 length *= 0.5
615 scale *= 2
616 # PGF guarantees that repeated loading is a no-op

Callers 3

draw_markersMethod · 0.95
draw_pathMethod · 0.95
_print_pgf_clipMethod · 0.95

Calls 5

_writelnFunction · 0.85
get_clip_rectangleMethod · 0.80
iter_segmentsMethod · 0.80
get_pointsMethod · 0.45
get_sketch_paramsMethod · 0.45

Tested by

no test coverage detected