Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 79ccf53

Browse filesBrowse files
njwhitetimhoffm
authored andcommitted
Allow SVG Text-as-Text to Use Data Coordinates (#14114)
* Allow SVG Text-as-Text to Use Data Coordinates * Review Feedback
1 parent c66f540 commit 79ccf53
Copy full SHA for 79ccf53

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed

‎lib/matplotlib/backends/backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_svg.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
10401040

10411041
# Get anchor coordinates.
10421042
transform = mtext.get_transform()
1043-
ax, ay = transform.transform_point(mtext.get_position())
1043+
ax, ay = transform.transform_point(
1044+
mtext.get_unitless_position())
10441045
ay = self.height - ay
10451046

10461047
# Don't do vertical anchor alignment. Most applications do not

‎lib/matplotlib/tests/test_backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_svg.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,20 @@ def test_unicode_won():
196196
won_id = 'Computer_Modern_Sans_Serif-142'
197197
assert re.search(r'<path d=(.|\s)*?id="{0}"/>'.format(won_id), buf)
198198
assert re.search(r'<use[^/>]*? xlink:href="#{0}"/>'.format(won_id), buf)
199+
200+
201+
def test_svgnone_with_data_coordinates():
202+
plt.rcParams['svg.fonttype'] = 'none'
203+
expected = 'Unlikely to appear by chance'
204+
205+
fig, ax = plt.subplots()
206+
ax.text(np.datetime64('2019-06-30'), 1, expected)
207+
ax.set_xlim(np.datetime64('2019-01-01'), np.datetime64('2019-12-31'))
208+
ax.set_ylim(0, 2)
209+
210+
with BytesIO() as fd:
211+
fig.savefig(fd, format='svg')
212+
fd.seek(0)
213+
buf = fd.read().decode()
214+
215+
assert expected in buf

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.