8000 MNT: Refine error message in path chunking · matplotlib/matplotlib@1ef4d39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ef4d39

Browse files
herilalainaphobson
authored andcommitted
MNT: Refine error message in path chunking
* Added exception handling * Added chunksize test for backend agg
1 parent a7c0ea7 commit 1ef4d39

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,32 @@ def draw_path(self, gc, path, transform, rgbFace=None):
147147
"""
148148
nmax = rcParams['agg.path.chunksize'] # here at least for testing
149149
npts = path.vertices.shape[0]
150+
150151
if (nmax > 100 and npts > nmax and path.should_simplify and
151152
rgbFace is None and gc.get_hatch() is None):
152-
nch = np.ceil(npts/float(nmax))
153-
chsize = int(np.ceil(npts/nch))
153+
nch = np.ceil(npts / float(nmax))
154+
chsize = int(np.ceil(npts / nch))
154155
i0 = np.arange(0, npts, chsize)
155156
i1 = np.zeros_like(i0)
156157
i1[:-1] = i0[1:] - 1
157158
i1[-1] = npts
158159
for ii0, ii1 in zip(i0, i1):
159-
v = path.vertices[ii0:ii1,:]
160+
v = path.vertices[ii0:ii1, :]
160161
c = path.codes
161162
if c is not None:
162163
c = c[ii0:ii1]
163-
c[0] = Path.MOVETO # move to end of last chunk
164+
c[0] = Path.MOVETO # move to end of last chunk
164165
p = Path(v, c)
165-
self._renderer.draw_path(gc, p, transform, rgbFace)
166+
try:
167+
self._renderer.draw_path(gc, p, transform, rgbFace)
168+
except OverflowError:
169+
raise OverflowError("Exceeded cell block limit (set 'agg.path.chunksize' rcparam)")
166170
else:
167-
self._renderer.draw_path(gc, path, transform, rgbFace)
171+
try:
172+
self._renderer.draw_path(gc, path, transform, rgbFace)
173+
except OverflowError:
174+
raise OverflowError("Exceeded cell block limit (set 'agg.path.chunksize' rcparam)")
175+
168176

169177
def draw_mathtext(self, gc, x, y, s, prop, angle):
170178
"""

lib/matplotlib/tests/test_agg.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib.testing.decorators import image_comparison
1515
from matplotlib import pyplot as plt
1616
from matplotlib import collections
17-
from matplotlib import path
17+
from matplotlib import path, rcParams
1818
from matplotlib import transforms as mtransforms
1919

2020

@@ -219,3 +219,18 @@ def test_too_large_image():
219219
buff = io.BytesIO()
220220
with pytest.raises(ValueError):
221221
fig.savefig(buff)
222+
223+
224+
def test_chunksize():
225+
x = range(200)
226+
227+
# Test without chunksize
228+
fig, ax = plt.subplots()
229+
ax.plot(x, np.sin(x))
230+
fig.canvas.draw()
231+
232+
# Test with chunksize
233+
fig, ax = plt.subplots()
234+
rcParams['agg.path.chunksize'] = 105
235+
ax.plot(x, np.sin(x))
236+
fig.canvas.draw()

0 commit comments

Comments
 (0)
0