Skip to content

Commit 82cbb29

Browse files
tacaswellanntzer
andcommitted
FIX: Make sure we do not over-write eps short cuts
This tests that we have not re-defined a short-cut by checking that we do not have two `/name` lines in the output file. closes #21509 Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parent f93c0a3 commit 82cbb29

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def _get_clip_cmd(self, gc):
429429
key = (path, id(trf))
430430
custom_clip_cmd = self._clip_paths.get(key)
431431
if custom_clip_cmd is None:
432-
custom_clip_cmd = "c%x" % len(self._clip_paths)
432+
custom_clip_cmd = "c%d" % len(self._clip_paths)
433433
self._pswriter.write(f"""\
434434
/{custom_clip_cmd} {{
435435
{self._convert_path(path, trf, simplify=False)}
@@ -570,7 +570,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
570570
path_codes = []
571571
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
572572
master_transform, paths, all_transforms)):
573-
name = 'p%x_%x' % (self._path_collection_id, i)
573+
name = 'p%d_%d' % (self._path_collection_id, i)
574574
path_bytes = self._convert_path(path, transform, simplify=False)
575575
self._pswriter.write(f"""\
576576
/{name} {{

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import io
1+
from collections import Counter
22
from pathlib import Path
3+
import io
34
import re
45
import tempfile
56

67
import pytest
78

8-
import matplotlib as mpl
9-
import matplotlib.pyplot as plt
109
from matplotlib import cbook, patheffects
11-
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1210
from matplotlib.cbook import MatplotlibDeprecationWarning
13-
11+
from matplotlib.figure import Figure
12+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
13+
import matplotlib as mpl
14+
import matplotlib.pyplot as plt
1415

1516
needs_ghostscript = pytest.mark.skipif(
1617
"eps" not in mpl.testing.compare.converter,
@@ -244,3 +245,23 @@ def test_linedash():
244245
fig.savefig(buf, format="ps")
245246

246247
assert buf.tell() > 0
248+
249+
250+
def test_no_definintion():
251+
252+
fig = Figure()
253+
axs = fig.subplots(4, 4, subplot_kw=dict(projection="polar"))
254+
for ax in axs.flat:
255+
ax.set(xticks=[], yticks=[])
256+
ax.plot([1, 2])
257+
fig.suptitle("hello, world")
258+
259+
buf = io.StringIO()
260+
fig.savefig(buf, format='eps')
261+
buf.seek(0)
262+
263+
wds = [ln.partition(' ')[0] for
264+
ln in buf.readlines()
265+
if ln.startswith('/')]
266+
267+
assert max(Counter(wds).values()) == 1

0 commit comments

Comments
 (0)