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

Method draw_tex

lib/matplotlib/backends/backend_ps.py:721–760  ·  view source on GitHub ↗
(self, gc, x, y, s, prop, angle, *, mtext=None)

Source from the content-addressed store, hash-verified

719
720 @_log_if_debug_on
721 def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
722 # docstring inherited
723 if self._is_transparent(gc.get_rgb()):
724 return # Special handling for fully transparent.
725
726 if not hasattr(self, "psfrag"):
727 self._logwarn_once(
728 "The PS backend determines usetex status solely based on "
729 "rcParams['text.usetex'] and does not support having "
730 "usetex=True only for some elements; this element will thus "
731 "be rendered as if usetex=False.")
732 self.draw_text(gc, x, y, s, prop, angle, False, mtext)
733 return
734
735 w, h, bl = self.get_text_width_height_descent(s, prop, ismath="TeX")
736 fontsize = prop.get_size_in_points()
737 thetext = 'psmarker%d' % self.textcnt
738 color = _nums_to_str(*gc.get_rgb()[:3], sep=',')
739 fontcmd = {'sans-serif': r'{\sffamily %s}',
740 'monospace': r'{\ttfamily %s}'}.get(
741 mpl.rcParams['font.family'][0], r'{\rmfamily %s}')
742 s = fontcmd % s
743 tex = r'\color[rgb]{%s} %s' % (color, s)
744
745 # Stick to bottom-left alignment, so subtract descent from the text-normal
746 # direction since text is normally positioned by its baseline.
747 rangle = np.radians(angle + 90)
748 pos = _nums_to_str(x - bl * np.cos(rangle), y - bl * np.sin(rangle))
749 self.psfrag.append(
750 r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}' % (
751 thetext, angle, fontsize, fontsize*1.25, tex))
752
753 self._pswriter.write(f"""\
754gsave
755{pos} moveto
756({thetext})
757show
758grestore
759""")
760 self.textcnt += 1
761
762 @_log_if_debug_on
763 def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):

Callers 1

draw_textMethod · 0.95

Calls 7

_is_transparentMethod · 0.95
draw_textMethod · 0.95
_nums_to_strFunction · 0.85
get_rgbMethod · 0.45
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected