Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ismath == 'TeX':
fontsize = prop.get_size_in_points()
w, h, d = self.texmanager.get_text_width_height_descent(
s, fontsize, renderer=self)
return w, h, d
if ismath:
ox, oy, width, height, descent, fonts, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
return width, height, descent
# family = prop.get_family()
# weight = prop.get_weight()
# style = prop.get_style()
s = s.replace(u'\u2212', '-').encode("latin-1")
fontsize = prop.get_size_in_points()
gr.setcharheight(fontsize * 0.0013)
gr.setcharup(0, 1)
(tbx, tby) = gr.inqtextext(0, 0, s)
width, height, descent = tbx[1], tby[2], 0
return width, height, descent
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if ismath:
self._draw_mathtext(gc, x, y, s, prop, angle)
else:
x, y = gr.wctondc(x, y)
s = s.replace(u'\u2212', '-')
fontsize = prop.get_size_in_points()
rgba = gc.get_rgb()[:4]
color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
gr.settransparency(rgba[3])
gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
gr.setcharheight(fontsize * 0.0013)
gr.settextcolorind(color)
if angle != 0:
gr.setcharup(-np.sin(angle * np.pi/180),
np.cos(angle * np.pi/180))
else:
gr.setcharup(0, 1)
gr.text(x, y, s.encode("latin-1"))
p0 = coord.getNDC()
x, y = p0.x, p0.y
charHeight = self.charheight * self._axes.sizey
window = gr.inqwindow()
# set viewport and window to NDC to allow 'line-drawing'
# in all regions and in NDC coordinates
# if hideviewport is False.
gr.setviewport(0, self._axes.sizex, 0, self._axes.sizey)
gr.setwindow(0, self._axes.sizex, 0, self._axes.sizey)
else:
x, y = self.x, self.y
charHeight = self.charheight
gr.setcharheight(charHeight)
gr.setcharup(*self.charup)
gr.settextalign(self.halign, self.valign)
gr.settextpath(self.textpath)
gr.setcharexpan(self.charexpan)
if self._font is not None and self._precision is not None:
gr.settextfontprec(self._font, self._precision)
tbx, tby = gr.inqtext(x, y, self.text)
if self._axes:
gr.setviewport(*self._axes.viewportscaled)
gr.setwindow(*window)
return tbx, tby
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if ismath:
self._draw_mathtext(gc, x, y, s, prop, angle)
else:
x, y = gr.wctondc(x, y)
fontsize = prop.get_size_in_points()
rgba = gc.get_rgb()[:4]
color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
gr.settransparency(rgba[3])
gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
gr.setcharheight(fontsize * self.nominal_fontsize)
gr.settextcolorind(color)
if angle != 0:
gr.setcharup(-np.sin(angle * np.pi/180),
np.cos(angle * np.pi/180))
else:
gr.setcharup(0, 1)
gr.text(x, y, s)
if ismath:
self._draw_mathtext(gc, x, y, s, prop, angle)
else:
x, y = gr.wctondc(x, y)
fontsize = prop.get_size_in_points()
rgba = gc.get_rgb()[:4]
color = gr.inqcolorfromrgb(rgba[0], rgba[1], rgba[2])
gr.settransparency(rgba[3])
gr.setcolorrep(color, rgba[0], rgba[1], rgba[2])
gr.setcharheight(fontsize * self.nominal_fontsize)
gr.settextcolorind(color)
if angle != 0:
gr.setcharup(-np.sin(angle * np.pi/180),
np.cos(angle * np.pi/180))
else:
gr.setcharup(0, 1)
gr.text(x, y, s)
dyXLabel = 0
dxYLabel = 0
# -- draw x- and y label ---------------------------------------------
y = self.offsetXLabel + self.viewport[2]
if self.xlabel:
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.setcharup(0., 1.)
# tby = gr.inqtext(0, 0, self.xlabel)[1]
# tby = map(lambda y: gr.wctondc(0, y)[1], tby)
# dyXLabel = max(tby) - min(tby) # already scaled
dyXLabel = charHeightUnscaled
y -= dyXLabel + charHeightUnscaled
gr.text(xmin + (xmax - xmin) / 2., y * self.sizey, self.xlabel)
if self.ylabel:
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.setcharup(-1., 0.)
tbx = gr.inqtext(0, 0, self.ylabel)[0]
tbx = [gr.wctondc(0, yi)[0] for yi in tbx]
dxYLabel = max(tbx) - min(tbx)
gr.text(self.offsetYLabel + xmin - dxYLabel / 2. - .075,
ymin + (ymax - ymin) / 2., self.ylabel)
gr.setcharup(0., 1.)
# -- draw legend and calculate ROIs for legend items -----------------
if self._legend:
x, y = xmin, y - dyXLabel - charHeightUnscaled
if y < 0:
vp = self.viewport
vp[2] += dyXLabel
self.viewport = vp # propagate update (calls setter)
gr.clearws()
self.drawGR()
else:
}
vertical_alignment = {
'Top': 1,
'Cap': 2,
'Half': 3,
'Base': 4,
'Bottom': 5
}
gr.selntran(0)
gr.setcharheight(0.024)
for angle in range(361):
gr.setcharup(sin(-angle * pi / 180), cos(-angle * pi / 180))
gr.setmarkertype(2)
gr.clearws()
for halign in horizontal_alignment:
for valign in vertical_alignment:
gr.settextalign(horizontal_alignment[halign], vertical_alignment[valign])
x = -0.1 + horizontal_alignment[halign] * 0.3
y = 1.1 - vertical_alignment[valign] * 0.2
s = halign + '\n' + valign + '\n' + 'third line'
gr.polymarker([x], [y])
gr.text(x, y, s)
tbx, tby = gr.inqtext(x, y, s)
gr.fillarea(tbx, tby)
gr.updatews()
time.sleep(0.02)
if kind in ('wireframe', 'surface', 'plot3', 'scatter3', 'trisurf', 'volume'):
x_label = _plt.kwargs.get('xlabel', '')
y_label = _plt.kwargs.get('ylabel', '')
z_label = _plt.kwargs.get('zlabel', '')
gr.titles3d(x_label, y_label, z_label)
else:
if 'xlabel' in _plt.kwargs:
gr.savestate()
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_BOTTOM)
gr.textext(0.5 * (viewport[0] + viewport[1]), vp[2] + 0.5 * charheight, _plt.kwargs['xlabel'])
gr.restorestate()
if 'ylabel' in _plt.kwargs:
gr.savestate()
gr.settextalign(gr.TEXT_HALIGN_CENTER, gr.TEXT_VALIGN_TOP)
gr.setcharup(-1, 0)
gr.textext(vp[0] + 0.5 * charheight, 0.5 * (viewport[2] + viewport[3]), _plt.kwargs['ylabel'])
gr.restorestate()
if kind in ('bar'):
if 'xnotations' in _plt.kwargs:
x_notations = _plt.kwargs.pop('xnotations')
yval = _plt.args[0][2] if _plt.kwargs['multi_bar'] else _plt.args[0][1]
if len(x_notations) == len(yval):
window = _plt.kwargs['window']
gr.setcharheight(charheight)
gr.settextalign(2, 1)
for i in range(1, len(x_notations) + 1):
x = viewport[0] + ((viewport[1] - viewport[0]) * i) / (window[1] - window[0])
y = viewport[2] - 0.5 * charheight
gr.textext(x, y, x_notations[i - 1])
else:
p0 = coord.getNDC()
x, y = p0.x, p0.y
charHeight = self.charheight * self._axes.sizey
window = gr.inqwindow()
# set viewport and window to NDC to allow 'line-drawing'
# in all regions and in NDC coordinates
# if hideviewport is False.
gr.setviewport(0, self._axes.sizex, 0, self._axes.sizey)
gr.setwindow(0, self._axes.sizex, 0, self._axes.sizey)
else:
x, y = self.x, self.y
charHeight = self.charheight
gr.setcharheight(charHeight)
gr.setcharup(*self.charup)
gr.settextalign(self.halign, self.valign)
gr.settextpath(self.textpath)
gr.setcharexpan(self.charexpan)
if self._font is not None and self._precision is not None:
gr.settextfontprec(self._font, self._precision)
tbx, tby = gr.inqtext(x, y, self.text)
if self._axes:
gr.setviewport(*self._axes.viewportscaled)
gr.setwindow(*window)
return tbx, tby