diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 6cdc3ffd7594..dbb4466312d4 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1040,7 +1040,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): # Get anchor coordinates. transform = mtext.get_transform() - ax, ay = transform.transform_point(mtext.get_position()) + ax, ay = transform.transform_point( + mtext.get_unitless_position()) ay = self.height - ay # Don't do vertical anchor alignment. Most applications do not diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index f56f9f9595cc..e572547d0737 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -196,3 +196,20 @@ def test_unicode_won(): won_id = 'Computer_Modern_Sans_Serif-142' assert re.search(r''.format(won_id), buf) assert re.search(r']*? xlink:href="#{0}"/>'.format(won_id), buf) + + +def test_svgnone_with_data_coordinates(): + plt.rcParams['svg.fonttype'] = 'none' + expected = 'Unlikely to appear by chance' + + fig, ax = plt.subplots() + ax.text(np.datetime64('2019-06-30'), 1, expected) + ax.set_xlim(np.datetime64('2019-01-01'), np.datetime64('2019-12-31')) + ax.set_ylim(0, 2) + + with BytesIO() as fd: + fig.savefig(fd, format='svg') + fd.seek(0) + buf = fd.read().decode() + + assert expected in buf