diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 35c61b08f26b..8c88bfa3c732 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -429,7 +429,7 @@ def _get_clip_cmd(self, gc): key = (path, id(trf)) custom_clip_cmd = self._clip_paths.get(key) if custom_clip_cmd is None: - custom_clip_cmd = "c%x" % len(self._clip_paths) + custom_clip_cmd = "c%d" % len(self._clip_paths) self._pswriter.write(f"""\ /{custom_clip_cmd} {{ {self._convert_path(path, trf, simplify=False)} @@ -570,7 +570,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms, path_codes = [] for i, (path, transform) in enumerate(self._iter_collection_raw_paths( master_transform, paths, all_transforms)): - name = 'p%x_%x' % (self._path_collection_id, i) + name = 'p%d_%d' % (self._path_collection_id, i) path_bytes = self._convert_path(path, transform, simplify=False) self._pswriter.write(f"""\ /{name} {{ diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 50b1b0bc0cbe..f0d0cbdac722 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -1,16 +1,17 @@ -import io +from collections import Counter from pathlib import Path +import io import re import tempfile import pytest -import matplotlib as mpl -import matplotlib.pyplot as plt from matplotlib import cbook, patheffects -from matplotlib.testing.decorators import check_figures_equal, image_comparison from matplotlib.cbook import MatplotlibDeprecationWarning - +from matplotlib.figure import Figure +from matplotlib.testing.decorators import check_figures_equal, image_comparison +import matplotlib as mpl +import matplotlib.pyplot as plt needs_ghostscript = pytest.mark.skipif( "eps" not in mpl.testing.compare.converter, @@ -244,3 +245,23 @@ def test_linedash(): fig.savefig(buf, format="ps") assert buf.tell() > 0 + + +def test_no_duplicate_definition(): + + fig = Figure() + axs = fig.subplots(4, 4, subplot_kw=dict(projection="polar")) + for ax in axs.flat: + ax.set(xticks=[], yticks=[]) + ax.plot([1, 2]) + fig.suptitle("hello, world") + + buf = io.StringIO() + fig.savefig(buf, format='eps') + buf.seek(0) + + wds = [ln.partition(' ')[0] for + ln in buf.readlines() + if ln.startswith('/')] + + assert max(Counter(wds).values()) == 1