Skip to content

Commit 1915c83

Browse files
committed
[3020704] set_xlim() problem
Bug in PathClipper when vertices fall precisely on the clipping edge. svn path=/trunk/matplotlib/; revision=8461
1 parent 6b64386 commit 1915c83

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed
Binary file not shown.
Lines changed: 104 additions & 0 deletions
Loading

lib/matplotlib/tests/test_simplification.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ def test_throw_rendering_complexity_exceeded():
186186
else:
187187
rcParams['path.simplify'] = True
188188

189+
@image_comparison(baseline_images=['clipper_edge'])
190+
def test_clipper():
191+
dat = (0, 1, 0, 2, 0, 3, 0, 4, 0, 5)
192+
fig = plt.figure(figsize=(2, 1))
193+
fig.subplots_adjust(left = 0, bottom = 0, wspace = 0, hspace = 0)
194+
195+
ax = fig.add_axes((0, 0, 1.0, 1.0), ylim = (0, 5), autoscale_on = False)
196+
ax.plot(dat)
197+
ax.xaxis.set_major_locator(plt.MultipleLocator(1))
198+
ax.xaxis.set_major_formatter(plt.NullFormatter())
199+
ax.yaxis.set_major_locator(plt.MultipleLocator(1))
200+
ax.yaxis.set_major_formatter(plt.NullFormatter())
201+
ax.xaxis.set_ticks_position('bottom')
202+
ax.yaxis.set_ticks_position('left')
203+
204+
ax.set_xlim(5, 9)
205+
fig.savefig('clipper_edge')
189206

190207
if __name__=='__main__':
191208
import nose

src/path_converters.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,21 @@ class PathClipper
288288
PathClipper(VertexSource& source, bool do_clipping,
289289
double width, double height) :
290290
m_source(&source), m_do_clipping(do_clipping),
291-
m_cliprect(0.0, 0.0, width, height), m_moveto(true),
291+
m_cliprect(-1.0, -1.0, width + 1.0, height + 1.0), m_moveto(true),
292292
m_has_next(false)
293293
{
294294
// empty
295295
}
296296

297297
PathClipper(VertexSource& source, bool do_clipping,
298298
const agg::rect_base<double>& rect) :
299-
m_source(&source), m_do_clipping(do_clipping),
300-
m_cliprect(rect), m_moveto(true), m_has_next(false)
299+
m_source(&source), m_do_clipping(do_clipping),
300+
m_cliprect(rect), m_moveto(true), m_has_next(false)
301301
{
302-
// empty
302+
m_cliprect.x1 -= 1.0;
303+
m_cliprect.y1 -= 1.0;
304+
m_cliprect.x2 += 1.0;
305+
m_cliprect.y2 += 1.0;
303306
}
304307

305308
inline void

0 commit comments

Comments
 (0)