Draws the `.Text` object to the given *renderer*.
(self, renderer)
| 693 | |
| 694 | @artist.allow_rasterization |
| 695 | def draw(self, renderer): |
| 696 | """ |
| 697 | Draws the `.Text` object to the given *renderer*. |
| 698 | """ |
| 699 | if renderer is not None: |
| 700 | self._renderer = renderer |
| 701 | if not self.get_visible(): |
| 702 | return |
| 703 | if self.get_text() == '': |
| 704 | return |
| 705 | |
| 706 | renderer.open_group('text', self.get_gid()) |
| 707 | |
| 708 | with _wrap_text(self) as textobj: |
| 709 | bbox, info, descent = textobj._get_layout(renderer) |
| 710 | trans = textobj.get_transform() |
| 711 | |
| 712 | # don't use textobj.get_position here, which refers to text |
| 713 | # position in Text, and dash position in TextWithDash: |
| 714 | posx = float(textobj.convert_xunits(textobj._x)) |
| 715 | posy = float(textobj.convert_yunits(textobj._y)) |
| 716 | posx, posy = trans.transform_point((posx, posy)) |
| 717 | if not np.isfinite(posx) or not np.isfinite(posy): |
| 718 | _log.warning("posx and posy should be finite values") |
| 719 | return |
| 720 | canvasw, canvash = renderer.get_canvas_width_height() |
| 721 | |
| 722 | # draw the FancyBboxPatch |
| 723 | if textobj._bbox_patch: |
| 724 | textobj._draw_bbox(renderer, posx, posy) |
| 725 | |
| 726 | gc = renderer.new_gc() |
| 727 | gc.set_foreground(textobj.get_color()) |
| 728 | gc.set_alpha(textobj.get_alpha()) |
| 729 | gc.set_url(textobj._url) |
| 730 | textobj._set_gc_clip(gc) |
| 731 | |
| 732 | angle = textobj.get_rotation() |
| 733 | |
| 734 | for line, wh, x, y in info: |
| 735 | |
| 736 | mtext = textobj if len(info) == 1 else None |
| 737 | x = x + posx |
| 738 | y = y + posy |
| 739 | if renderer.flipy(): |
| 740 | y = canvash - y |
| 741 | clean_line, ismath = textobj.is_math_text(line, |
| 742 | self.get_usetex()) |
| 743 | |
| 744 | if textobj.get_path_effects(): |
| 745 | from matplotlib.patheffects import PathEffectRenderer |
| 746 | textrenderer = PathEffectRenderer( |
| 747 | textobj.get_path_effects(), renderer) |
| 748 | else: |
| 749 | textrenderer = renderer |
| 750 | |
| 751 | if textobj.get_usetex(): |
| 752 | textrenderer.draw_tex(gc, x, y, clean_line, |
no test coverage detected