Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79ccf53

Browse 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

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/backends/backend_svg.py

Lines 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

Lines 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)