Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 014f32d

Browse files
committed
Close clipped paths
1 parent ed0ce1a commit 014f32d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

lib/matplotlib/tests/test_colorbar.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from matplotlib import rcParams
1212
from matplotlib.colors import BoundaryNorm
1313
from matplotlib.cm import get_cmap
14+
from matplotlib import cm
1415
from matplotlib.colorbar import ColorbarBase
1516

1617

@@ -253,6 +254,33 @@ def test_colorbarbase():
253254
ColorbarBase(ax, plt.cm.bone)
254255

255256

257+
@image_comparison(
258+
baseline_images=['colorbar_closed_patch'],
259+
remove_text=True)
260+
def test_colorbar_closed_patch():
261+
fig = plt.figure(figsize=(8,6))
262+
ax1 = fig.add_axes([0.05, 0.85, 0.9, 0.1])
263+
ax2 = fig.add_axes([0.05, 0.65, 0.9, 0.1])
264+
ax3 = fig.add_axes([0.05, 0.45, 0.9, 0.1])
265+
ax4 = fig.add_axes([0.05, 0.25, 0.9, 0.1])
266+
ax5 = fig.add_axes([0.05, 0.05, 0.9, 0.1])
267+
268+
cmap = cm.jet
269+
cmap.set_under('w')
270+
cmap.set_over('w')
271+
272+
im = ax1.pcolormesh(np.linspace(0,10,16).reshape((4,4)))
273+
274+
plt.colorbar(im,cax=ax2,cmap=cmap,orientation='horizontal',
275+
extend='both',extendfrac=0.5)
276+
plt.colorbar(im,cax=ax3,cmap=cmap,orientation='horizontal',
277+
extend='both',)
278+
plt.colorbar(im,cax=ax4,cmap=cmap,orientation='horizontal',
279+
extend='both',extendrect=True)
280+
plt.colorbar(im,cax=ax5,cmap=cmap,orientation='horizontal',
281+
extend='neither')
282+
283+
256284
if __name__ == '__main__':
257285
import nose
258286
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/tests/test_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_clipping_of_log():
206206
# Because y coordinate -99 is outside the clip zone, the first
207207
# line segment is effectively removed. That means that the closepoly
208208
# operation must be replaced by a move to the first point.
209-
assert np.allclose(tcodes, [ M, M, L, L, L ])
209+
assert np.allclose(tcodes, [ M, M, L, L, L, C ])
210210

211211

212212
class NonAffineForTest(mtrans.Transform):

src/path_converters.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class PathClipper
253253
double m_nextX;
254254
double m_nextY;
255255
bool m_has_next;
256+
bool m_end_poly;
256257
double m_initX;
257258
double m_initY;
258259
bool m_has_init;
@@ -265,6 +266,7 @@ class PathClipper
265266
m_cliprect(-1.0, -1.0, width + 1.0, height + 1.0),
266267
m_moveto(true),
267268
m_has_next(false),
269+
m_end_poly(false),
268270
m_has_init(false),
269271
m_broke_path(false)
270272
{
@@ -277,6 +279,7 @@ class PathClipper
277279
m_cliprect(rect),
278280
m_moveto(true),
279281
m_has_next(false),
282+
m_end_poly(false),
280283
m_has_init(false),
281284
m_broke_path(false)
282285
{
@@ -300,6 +303,11 @@ class PathClipper
300303
if (m_do_clipping) {
301304
/* This is the slow path where we actually do clipping */
302305

306+
if (m_end_poly) {
307+
m_end_poly = false;
308+
return (agg::path_cmd_end_poly | agg::path_flags_close);
309+
}
310+
303311
if (m_has_next) {
304312
m_has_next = false;
305313
*x = m_nextX;
@@ -313,6 +321,7 @@ class PathClipper
313321
*x = m_initX;
314322
*y = m_initY;
315323
code = agg::path_cmd_line_to;
324+
m_end_poly = true;
316325
} else {
317326
continue;
318327
}

0 commit comments

Comments
 (0)