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

Skip to content

Commit 5c54324

Browse files
committed
Preserve whitespace in svg output.
See https://www.w3.org/TR/css-text-3/#white-space-property, which replaces the deprecated https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xml:space (which wasn't used before either).
1 parent 093d582 commit 5c54324

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ def _write_default_style(self):
318318
writer = self.writer
319319
default_style = generate_css({
320320
'stroke-linejoin': 'round',
321-
'stroke-linecap': 'butt'})
321+
'stroke-linecap': 'butt',
322+
'white-space': 'pre',
323+
})
322324
writer.start('defs')
323325
writer.start('style', type='text/css')
324326
writer.data('*{%s}\n' % default_style)
Lines changed: 24 additions & 0 deletions
Loading

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ def test_text_urls():
7676
assert expected in buf
7777

7878

79+
@image_comparison(baseline_images=['white_space_pre'], extensions=['svg'])
80+
def test_white_space_pre():
81+
plt.rcParams["svg.fonttype"] = "none"
82+
fig = plt.figure()
83+
fig.text(.5, .5, "a b c")
84+
85+
7986
@image_comparison(baseline_images=['bold_font_output'], extensions=['svg'])
8087
def test_bold_font_output():
8188
fig = plt.figure()

0 commit comments

Comments
 (0)