Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Propagate mpl.text.Text instances to the backends and fix documentation #1081

Merged
merged 5 commits into from

5 participants

@pwuertz
Collaborator

This patch addresses the issue #353. Some backends could really benefit from the text alignment information that is present in mpl.text.Text instances. For instance, editing a pdf or svg would be much easier if the text elements were anchored as intended.

In contrast to the documentation of RendererBase.draw_text, a backend only receives a simple string instead of a Text instance. The patch simply adds the optional "mtext" kwarg that is used to propagate Text instances to the backends without changing the way text rendering is handled in any way. I also ran the tests from tests.py and everything seems to be fine.

@mdboom
Owner

This is a good idea -- and yes, that's a totally bogus docstring. I think before merging this, however, I'd like to see it developed to the point of actually using the text object within the backend to see how that plays out and all the details make sense. (It could just be on one backend for now). One thing that will have to change is that the (x, y) sent to the backend needs to become the anchor point, not always the lower left as it is now.

@pwuertz
Collaborator

My idea was that the current way of text handling is not to be interfered with. That means the arguments (x, y) still point to the position of the lower left as calculated by matplotlib. If you want to (optionally) anchor it yourself just lookup (x, y, va, ha) from mtext where (x, y) points to the (va, ha) anchor.

I was wondering why the mtexts were not given to the backends as documented in the first place, but you are doing some latex related filtering of the string as it seems. Also, if someone implements an artist that wants to layout and draw a lot of text elements he could do so by calling draw_text without any of the texts existing as mtext instances. So it's probably a good thing to only use this as an option :)

For demonstration I could re-enable anchoring support in the pgf backend. I did a workaround once by walking through the figure text instances which was rather painful due to text elements popping up that shouldn't have been rendered. The anchoring was working with the exception of rotated texts. This would take a little bit more time to implement because matplotlib interprets anchors and rotations differently than tikz/pgf. Nevertheless, it was a huge improvement since all texts were perfectly aligned even when changing the fonts afterwards.

@mdboom
Owner

I agree that this seems like the right approach to get text alignment information to the backend, that avoids some of the issues you saw with other approaches.

Yes -- the PGF backend would be a great test case of this. The anchoring of angled text is like nothing I've seen anywhere outside of matplotlib -- it's also a mismatch for PDF and SVG etc., but that's a tough thing to change without breaking backward compatibility. Whatever calculation on the anchor point that needs to be performed should perhaps be added to the Text object itself so that all backends can share that code.

I'd like to add support for this in SVG, PDF and PS as well (in that order, I think, because SVG being the most easily editable, it's really important there.) Hopefully between the two of us we can at least get SVG done before the freeze. I think that has the potential to be a very compelling feature for a lot of people.

@mdboom
Owner

This closes #353.

@pwuertz
Collaborator

Rotated text is a bit tough indeed. My problem at first was to figure out the behavior in matplotlib. From what I've seen it is the axis aligned bounding box of a rotated text that is being aligned. For tikz/pgf the text anchor point is also the pivot point for rotations, but bounding box alignment must be done manually I'm afraid :/. Both definitions have their drawbacks. I don't know how SVG and PDF define the pivot points for rotations with respect to text anchors.

Maybe it's a good idea to take a step back and collect information about which pivot point definitions are easiest to support in SVG, PDF, PS and PGF. For pgf/tikz aligning text to pivot point - easy, aligning rotated bounding box - ugly but possible.

In any case I think merging this PR will make it more easy to experiment with text-align support + there are no drawbacks. The worst thing that could happen is that at some point when implementing anchoring it could appear favorable to redefine the definition of pivot points ^^.

@pwuertz
Collaborator

This will produce a SVG where no-math-not-rotated text elements are horizontally anchored. Unfortunately I found a major show-stopper concerning SVG. Nobody seems to implement vertical text alignment :(. Chrome has some support, but no luck with inkscape cairo firefox etc.

(outdated example)

@mdboom
Owner

That's a bummer about the SVG vertical text alignment support. But I think it's still most useful to have the horizontal text alignment working. The most common use case is probably editing the title and having the text stay centered -- that works in this scenario, so it's still a win.

@mdboom
Owner

I think this is probably ready to merge -- but we should create a new issue for the fact that PDF and PS don't use the alignment information directly.

@pwuertz
Collaborator

Could you merge the PGF backend first? The mtext kwarg must be added to all backends, so once backend_pgf is merged to master I'll modify this PR and it will be ready to merge too.

@mdboom
Owner

Sure. The PGF stuff should probably get merged today.

@pwuertz
Collaborator

All right, I fixed up the first commit so it includes backend_pgf as well and re-ran all tests. The PR should be good to go.

@leejjoon
Owner

Just a note. The "rotation_mode"attribute of Text is meant to make the given position as an anchoring point of rotation.

@pwuertz
Collaborator

That's perfect, thanks leejjjoon! One could check that property and support anchored rotation then.

@pwuertz
Collaborator

The alignment of text elements is now included in the pgf output. When switching fonts within TeX documents, the texts are staying aligned nicely regardless of the new font metrics.

@pwuertz
Collaborator

The SVG backend now also aligns anchor-rotated text elements.

Due to the lack of 'alignment-baseline' support in most applications only the left/right/center alignment is done in SVG, the position in the vertical direction of the text is fixed. By the way, backend_svg did not handle the font decent for anchor-rotated text correctly. This is fixed now.

Example:

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('svg', fonttype='none')

plt.plot(range(5), ".")
plt.xlabel("x-label")
plt.ylabel("y-label")
plt.text(2, 2, "- xXgXx -", rotation=45, rotation_mode="anchor",
         va="bottom", ha="center")
plt.savefig("edit_this_with_inkscape.svg")

This is the output of the code. You should be able to edit the y-label and a 45° rotated text in inkscape with center alignment now:
https://gist.github.com/raw/3351009/381d916bb1184135a9dabc2c963d4aff91ee9291/edit_this_with_inkscape.svg

@jenshnielsen

Finally I a had a chance to test this out. The new behavior of the svg is a huge improvement and it is really cool
to be able to change the text directly within a latex document and having the text staying nicely aligned in the plot.

@pwuertz
Collaborator

Merge as a new feature to master?

@pwuertz
Collaborator

@mdboom , @leejjoon Is this good to merge?

@mdboom
Owner

I think this is cool enough for a "What's New" entry and probably should go in the CHANGELOG as well. The existing SVG tests should be sufficient to test this. Other than that, looks good to me.

@pwuertz
Collaborator

I applied the suggested changes. The travis setup for python3 seems to be broken at the moment, local testing succeeded however.

@jenshnielsen

Cool. The Travis issue looks like this one numpy/numpy#2761

@dmcdougall dmcdougall merged commit 4ef9115 into matplotlib:master
@pwuertz pwuertz referenced this pull request from a commit in pwuertz/matplotlib
@pwuertz pwuertz fix issue #1572 caused by PR #1081 44bd697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2012
  1. @pwuertz

    propagate mpl.text.Text instances to backends, fix documentation

    pwuertz authored pwuertz committed
  2. @pwuertz

    backend_svg: horizontal text alignment for anchored rotations

    pwuertz authored pwuertz committed
  3. @pwuertz

    use anchored rotation for y-labels

    pwuertz authored pwuertz committed
  4. @pwuertz

    backend_pgf: implement anchoring of text elements

    pwuertz authored pwuertz committed
  5. @pwuertz
This page is out of date. Refresh to see the latest.
View
5 CHANGELOG
@@ -1,3 +1,8 @@
+2012-11-27 Added the *mtext* parameter for supplying matplotlib.text.Text
+ instances to RendererBase.draw_tex and RendererBase.draw_text.
+ This allows backends to utilize additional text attributes, like
+ the alignment of text elements. - pwuertz
+
2012-11-16 plt.set_cmap no longer throws errors if there is not already
an active colorable artist, such as an image, and just sets
up the colormap to use from that point forward. - PI
View
8 doc/users/whats_new.rst
@@ -41,6 +41,14 @@ the whole figure. This was already the behavior for both
:func:`~matplotlib.pyplot.axes` and :func:`~matplotlib.pyplot.subplots`, and
now this consistency is shared with :func:`~matplotlib.pyplot.subplot`.
+Anchored text support
+---------------------
+The `svg` and `pgf` backends are now able to save text alignment information
+to their output formats. This allows to edit text elements in saved figures,
+using Inkscape for example, while preserving their intended position. For
+`svg` please note that you'll have to disable the default text-to-path
+conversion (`mpl.rc('svg', fonttype='none')`).
+
.. _whats-new-1-2:
new in matplotlib-1.2
View
5 lib/matplotlib/axis.py
@@ -1847,9 +1847,10 @@ def _get_label(self):
size=rcParams['axes.labelsize'],
weight=rcParams['axes.labelweight']),
color=rcParams['axes.labelcolor'],
- verticalalignment='center',
- horizontalalignment='right',
+ verticalalignment='bottom',
+ horizontalalignment='center',
rotation='vertical',
+ rotation_mode='anchor',
)
label.set_transform(mtransforms.blended_transform_factory(
mtransforms.IdentityTransform(), self.axes.transAxes))
View
9 lib/matplotlib/backend_bases.py
@@ -443,12 +443,12 @@ def option_scale_image(self):
"""
return False
- def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
"""
"""
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Draw the text instance
@@ -462,7 +462,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
the y location of the text in display coords
*s*
- a :class:`matplotlib.text.Text` instance
+ the text string
*prop*
a :class:`matplotlib.font_manager.FontProperties` instance
@@ -470,6 +470,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
*angle*
the rotation angle in degrees
+ *mtext*
+ a :class:`matplotlib.text.Text` instance
+
**backend implementers note**
When you are trying to determine if you have gotten your bounding box
View
4 lib/matplotlib/backends/backend_agg.py
@@ -158,7 +158,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
y = int(y) - oy
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)
- def draw_text(self, gc, x, y, s, prop, angle, ismath):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Render the text
"""
@@ -215,7 +215,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
return w, h, d
- def draw_tex(self, gc, x, y, s, prop, angle):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
# todo, handle props, angle, origins
size = prop.get_size_in_points()
View
2  lib/matplotlib/backends/backend_cairo.py
@@ -177,7 +177,7 @@ def draw_image(self, gc, x, y, im):
im.flipud_out()
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# Note: x,y are device/display coords, not user-coords, unlike other
# draw_* methods
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
View
2  lib/matplotlib/backends/backend_emf.py
@@ -358,7 +358,7 @@ def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
if debugPrint: print("draw_rectangle: optimizing away (%f,%f) w=%f,h=%f" % (x,y,width,height))
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Draw the text.Text instance s at x,y (display coords) with font
properties instance prop at angle in degrees, using GraphicsContext gc
View
2  lib/matplotlib/backends/backend_gdk.py
@@ -138,7 +138,7 @@ def draw_image(self, gc, x, y, im):
im.flipud_out()
- def draw_text(self, gc, x, y, s, prop, angle, ismath):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
x, y = int(x), int(y)
if x < 0 or y < 0: # window has shrunk and text is off the edge
View
4 lib/matplotlib/backends/backend_macosx.py
@@ -111,7 +111,7 @@ def draw_image(self, gc, x, y, im):
*gc.get_clip_path())
im.flipud_out()
- def draw_tex(self, gc, x, y, s, prop, angle):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
# todo, handle props, angle, origins
size = prop.get_size_in_points()
texmanager = self.get_texmanager()
@@ -128,7 +128,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
self.mathtext_parser.parse(s, self.dpi, prop)
gc.draw_mathtext(x, y, angle, 255 - image.as_array())
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ 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:
View
4 lib/matplotlib/backends/backend_pdf.py
@@ -1671,7 +1671,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
# Pop off the global transformation
self.file.output(Op.grestore)
- def draw_tex(self, gc, x, y, s, prop, angle):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
texmanager = self.get_texmanager()
fontsize = prop.get_size_in_points()
dvifile = texmanager.make_dvi(s, fontsize)
@@ -1763,7 +1763,7 @@ def encode_string(self, s, fonttype):
return s.encode('cp1252', 'replace')
return s.encode('utf-16be', 'replace')
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# TODO: combine consecutive texts into one BT/ET delimited section
# This function is rather complex, since there is no way to
View
94 lib/matplotlib/backends/backend_pgf.py
@@ -595,30 +595,53 @@ def draw_image(self, gc, x, y, im):
writeln(self.fh, r"\pgftext[at=\pgfqpoint{%fin}{%fin},left,bottom]{\pgfimage[interpolate=true,width=%fin,height=%fin]{%s}}" % (x * f, y * f, w * f, h * f, fname_img))
writeln(self.fh, r"\end{pgfscope}")
- def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!"):
- self.draw_text(gc, x, y, s, prop, angle, ismath)
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!", mtext=None):
+ self.draw_text(gc, x, y, s, prop, angle, ismath, mtext)
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
+ # prepare string for tex
s = common_texification(s)
-
- # apply font properties
prop_cmds = _font_properties_str(prop)
s = ur"{%s %s}" % (prop_cmds, s)
- # draw text at given coordinates
- x = x * 1. / self.dpi
- y = y * 1. / self.dpi
+
writeln(self.fh, r"\begin{pgfscope}")
+
alpha = gc.get_alpha()
if alpha != 1.0:
writeln(self.fh, r"\pgfsetfillopacity{%f}" % alpha)
writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % alpha)
- stroke_rgb = tuple(gc.get_rgb())[:3]
- if stroke_rgb != (0, 0, 0):
- writeln(self.fh, r"\definecolor{textcolor}{rgb}{%f,%f,%f}" % stroke_rgb)
+ rgb = tuple(gc.get_rgb())[:3]
+ if rgb != (0, 0, 0):
+ writeln(self.fh, r"\definecolor{textcolor}{rgb}{%f,%f,%f}" % rgb)
writeln(self.fh, r"\pgfsetstrokecolor{textcolor}")
writeln(self.fh, r"\pgfsetfillcolor{textcolor}")
- writeln(self.fh, "\\pgftext[left,bottom,x=%fin,y=%fin,rotate=%f]{%s}\n" % (x, y, angle, s))
+
+ f = 1.0 / self.figure.dpi
+ text_args = []
+ if angle == 0 or mtext.get_rotation_mode() == "anchor":
+ # if text anchoring can be supported, get the original coordinates
+ # and add alignment information
+ x, y = mtext.get_transform().transform_point(mtext.get_position())
+ text_args.append("x=%fin" % (x * f))
+ text_args.append("y=%fin" % (y * f))
+
+ halign = {"left": "left", "right": "right", "center": ""}
+ valign = {"top": "top", "bottom": "bottom",
+ "baseline": "base", "center": ""}
+ text_args.append(halign[mtext.get_ha()])
+ text_args.append(valign[mtext.get_va()])
+ else:
+ # if not, use the text layout provided by matplotlib
+ text_args.append("x=%fin" % (x * f))
+ text_args.append("y=%fin" % (y * f))
+ text_args.append("left")
+ text_args.append("bottom")
+
+ if angle != 0:
+ text_args.append("rotate=%f" % angle)
+
+ writeln(self.fh, r"\pgftext[%s]{%s}" % (",".join(text_args), s))
writeln(self.fh, r"\end{pgfscope}")
def get_text_width_height_descent(self, s, prop, ismath):
@@ -861,53 +884,6 @@ def print_png(self, fname_or_fh, *args, **kwargs):
else:
raise ValueError("filename must be a path or a file-like object")
- def _render_texts_pgf(self, fh):
- # TODO: currently unused code path
-
- # alignment anchors
- valign = {"top": "top", "bottom": "bottom", "baseline": "base", "center": ""}
- halign = {"left": "left", "right": "right", "center": ""}
- # alignment anchors for 90deg. rotated labels
- rvalign = {"top": "left", "bottom": "right", "baseline": "right", "center": ""}
- rhalign = {"left": "top", "right": "bottom", "center": ""}
-
- # TODO: matplotlib does not hide unused tick labels yet, workaround
- for tick in self.figure.findobj(mpl.axis.Tick):
- tick.label1.set_visible(tick.label1On)
- tick.label2.set_visible(tick.label2On)
- # TODO: strange, first legend label is always "None", workaround
- for legend in self.figure.findobj(mpl.legend.Legend):
- labels = legend.findobj(mpl.text.Text)
- labels[0].set_visible(False)
- # TODO: strange, legend child labels are duplicated,
- # find a list of unique text objects as workaround
- texts = self.figure.findobj(match=Text, include_self=False)
- texts = list(set(texts))
-
- # draw text elements
- for text in texts:
- s = text.get_text()
- if not s or not text.get_visible():
- continue
-
- s = common_texification(s)
-
- fontsize = text.get_fontsize()
- angle = text.get_rotation()
- transform = text.get_transform()
- x, y = transform.transform_point(text.get_position())
- x = x * 1.0 / self.figure.dpi
- y = y * 1.0 / self.figure.dpi
- # TODO: positioning behavior unknown for rotated elements
- # right now only the alignment for 90deg rotations is correct
- if angle == 90.:
- align = rvalign[text.get_va()] + "," + rhalign[text.get_ha()]
- else:
- align = valign[text.get_va()] + "," + halign[text.get_ha()]
-
- s = ur"{\fontsize{%f}{%f}\selectfont %s}" % (fontsize, fontsize*1.2, s)
- writeln(fh, ur"\pgftext[%s,x=%fin,y=%fin,rotate=%f]{%s}" % (align,x,y,angle,s))
-
def get_renderer(self):
return RendererPgf(self.figure, None)
View
4 lib/matplotlib/backends/backend_ps.py
@@ -649,7 +649,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
self._path_collection_id += 1
- def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
"""
draw a Text instance
"""
@@ -684,7 +684,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
self._pswriter.write(ps)
self.textcnt += 1
- def draw_text(self, gc, x, y, s, prop, angle, ismath):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
draw a Text instance
"""
View
52 lib/matplotlib/backends/backend_svg.py
@@ -815,7 +815,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
def _adjust_char_id(self, char_id):
return char_id.replace(u"%20", u"_")
- def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
+ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
"""
draw the text by converting them to paths using textpath module.
@@ -940,7 +940,7 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
writer.end('g')
- def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
+ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
writer = self.writer
color = rgb2hex(gc.get_rgb())
@@ -953,7 +953,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
if not ismath:
font = self._get_font(prop)
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
- y -= font.get_descent() / 64.0
+ descent = font.get_descent() / 64.0
+ y -= descent
fontsize = prop.get_size_in_points()
@@ -967,11 +968,40 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
style[u'font-style'] = prop.get_style().lower()
attrib[u'style'] = generate_css(style)
- attrib[u'transform'] = generate_transform([
- (u'translate', (x, y)),
- (u'rotate', (-angle,))])
+ if angle == 0 or mtext.get_rotation_mode() == "anchor":
+ # If text anchoring can be supported, get the original
+ # coordinates and add alignment information.
+
+ # Get anchor coordinates.
+ transform = mtext.get_transform()
+ ax, ay = transform.transform_point(mtext.get_position())
+ ay = self.height - ay
+
+ # Don't do vertical anchor alignment. Most applications do not
+ # support 'alignment-baseline' yet. Apply the vertical layout
+ # to the anchor point manually for now.
+ angle_rad = angle * np.pi / 180.
+ dir_vert = np.array([np.sin(angle_rad), np.cos(angle_rad)])
+ y += descent # Undo inappropriate text descent handling
+ v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
+ ax = ax + (v_offset - descent) * dir_vert[0]
+ ay = ay + (v_offset - descent) * dir_vert[1]
+
+ ha_mpl_to_svg = {'left': 'start', 'right': 'end',
+ 'center': 'middle'}
+ style[u'text-anchor'] = ha_mpl_to_svg[mtext.get_ha()]
+
+ attrib[u'x'] = str(ax)
+ attrib[u'y'] = str(ay)
+ attrib[u'style'] = generate_css(style)
+ attrib[u'transform'] = u"rotate(%f, %f, %f)" % (-angle, ax, ay)
+ writer.element(u'text', s, attrib=attrib)
+ else:
+ attrib[u'transform'] = generate_transform([
+ (u'translate', (x, y)),
+ (u'rotate', (-angle,))])
- writer.element(u'text', s, attrib=attrib)
+ writer.element(u'text', s, attrib=attrib)
if rcParams['svg.fonttype'] == 'svgfont':
fontset = self._fonts.setdefault(font.fname, set())
@@ -1053,10 +1083,10 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
writer.end(u'g')
- def draw_tex(self, gc, x, y, s, prop, angle):
+ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
- def draw_text(self, gc, x, y, s, prop, angle, ismath):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
clipid = self._get_clip(gc)
if clipid is not None:
# Cannot apply clip-path directly to the text, because
@@ -1065,9 +1095,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
u'g', attrib={u'clip-path': u'url(#%s)' % clipid})
if rcParams['svg.fonttype'] == 'path':
- self._draw_text_as_path(gc, x, y, s, prop, angle, ismath)
+ self._draw_text_as_path(gc, x, y, s, prop, angle, ismath, mtext)
else:
- self._draw_text_as_text(gc, x, y, s, prop, angle, ismath)
+ self._draw_text_as_text(gc, x, y, s, prop, angle, ismath, mtext)
if clipid is not None:
self.writer.end(u'g')
View
2  lib/matplotlib/backends/backend_template.py
@@ -104,7 +104,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
def draw_image(self, gc, x, y, im):
pass
- def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
pass
def flipy(self):
View
6 lib/matplotlib/backends/backend_wx.py
@@ -361,11 +361,7 @@ def draw_image(self, gc, x, y, im):
gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
gc.unselect()
- def draw_text(self, gc, x, y, s, prop, angle, ismath):
- """
- Render the matplotlib.text.Text instance
- None)
- """
+ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if ismath: s = self.strip_math(s)
DEBUG_MSG("draw_text()", 1, self)
gc.select()
View
9 lib/matplotlib/text.py
@@ -585,10 +585,11 @@ def draw(self, renderer):
if self.get_path_effects():
for path_effect in self.get_path_effects():
path_effect.draw_tex(renderer, gc, x, y, clean_line,
- self._fontproperties, angle)
+ self._fontproperties, angle,
+ mtext=self)
else:
renderer.draw_tex(gc, x, y, clean_line,
- self._fontproperties, angle)
+ self._fontproperties, angle, mtext=self)
else:
for line, wh, x, y in info:
if not np.isfinite(x) or not np.isfinite(y):
@@ -604,11 +605,11 @@ def draw(self, renderer):
for path_effect in self.get_path_effects():
path_effect.draw_text(renderer, gc, x, y, clean_line,
self._fontproperties, angle,
- ismath=ismath)
+ ismath=ismath, mtext=self)
else:
renderer.draw_text(gc, x, y, clean_line,
self._fontproperties, angle,
- ismath=ismath)
+ ismath=ismath, mtext=self)
gc.restore()
renderer.close_group('text')
Something went wrong with that request. Please try again.