| 374 | |
| 375 | |
| 376 | class RendererPgf(RendererBase): |
| 377 | |
| 378 | def __init__(self, figure, fh): |
| 379 | """ |
| 380 | Create a new PGF renderer that translates any drawing instruction |
| 381 | into text commands to be interpreted in a latex pgfpicture environment. |
| 382 | |
| 383 | Attributes |
| 384 | ---------- |
| 385 | figure : `~matplotlib.figure.Figure` |
| 386 | Matplotlib figure to initialize height, width and dpi from. |
| 387 | fh : file-like |
| 388 | File handle for the output of the drawing commands. |
| 389 | """ |
| 390 | |
| 391 | super().__init__() |
| 392 | self.dpi = figure.dpi |
| 393 | self.fh = fh |
| 394 | self.figure = figure |
| 395 | self.image_counter = 0 |
| 396 | |
| 397 | def draw_markers(self, gc, marker_path, marker_trans, path, trans, |
| 398 | rgbFace=None): |
| 399 | # docstring inherited |
| 400 | |
| 401 | _writeln(self.fh, r"\begin{pgfscope}") |
| 402 | |
| 403 | # convert from display units to in |
| 404 | f = 1. / self.dpi |
| 405 | |
| 406 | # set style and clip |
| 407 | self._print_pgf_clip(gc) |
| 408 | self._print_pgf_path_styles(gc, rgbFace) |
| 409 | |
| 410 | # build marker definition |
| 411 | bl, tr = marker_path.get_extents(marker_trans).get_points() |
| 412 | coords = bl[0] * f, bl[1] * f, tr[0] * f, tr[1] * f |
| 413 | _writeln(self.fh, |
| 414 | r"\pgfsys@defobject{currentmarker}" |
| 415 | r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords) |
| 416 | self._print_pgf_path(None, marker_path, marker_trans) |
| 417 | self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, |
| 418 | fill=rgbFace is not None) |
| 419 | _writeln(self.fh, r"}") |
| 420 | |
| 421 | maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX. |
| 422 | clip = (-maxcoord, -maxcoord, maxcoord, maxcoord) |
| 423 | |
| 424 | # draw marker for each vertex |
| 425 | for point, code in path.iter_segments(trans, simplify=False, |
| 426 | clip=clip): |
| 427 | x, y = point[0] * f, point[1] * f |
| 428 | _writeln(self.fh, r"\begin{pgfscope}") |
| 429 | _writeln(self.fh, r"\pgfsys@transformshift{%fin}{%fin}" % (x, y)) |
| 430 | _writeln(self.fh, r"\pgfsys@useobject{currentmarker}{}") |
| 431 | _writeln(self.fh, r"\end{pgfscope}") |
| 432 | |
| 433 | _writeln(self.fh, r"\end{pgfscope}") |
no outgoing calls
no test coverage detected
searching dependent graphs…