Skip to content

FIX: Make sure we do not over-write eps short cuts #21617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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} {{
Expand Down
31 changes: 26 additions & 5 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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