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

Skip to content

Commit dcc542b

Browse files
committed
Elimination of contourf cut strokes: second try
svn path=/trunk/matplotlib/; revision=7356
1 parent 47c1fd3 commit dcc542b

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ def __init__(self, ax, *args, **kwargs):
606606
segs = nlist[:nseg]
607607
kinds = nlist[nseg:]
608608

609-
610609
paths = self._make_paths(segs, kinds)
611610

612611
col = collections.PathCollection(paths,
@@ -652,8 +651,10 @@ def _make_paths(segs, kinds):
652651
codes = np.zeros(kind.shape, dtype=mpath.Path.code_type)
653652
codes.fill(mpath.Path.LINETO)
654653
codes[0] = mpath.Path.MOVETO
655-
# Attempted slit removal is disabled until we get it right.
656-
#codes[kind >= _cntr._slitkind] = mpath.Path.MOVETO
654+
# points that begin a slit or are in it:
655+
in_slit = kind[:-1] >= _cntr._slitkind
656+
# use moveto for any point *following* such a point
657+
codes[1:][in_slit] = mpath.Path.MOVETO
657658
paths.append(mpath.Path(seg, codes))
658659
return paths
659660

src/cntr.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ void cntr_del(Csite *site)
13261326

13271327

13281328
/* Build a list of XY 2-D arrays, shape (N,2), to which a list of K arrays
1329-
is concatenated concatenated. */
1329+
is concatenated. */
13301330
static PyObject *
13311331
build_cntr_list_v2(long *np, double *xp, double *yp, short *kp,
13321332
int nparts, long ntotal)
@@ -1653,6 +1653,29 @@ Cntr_trace(Cntr *self, PyObject *args, PyObject *kwds)
16531653
return cntr_trace(self->site, levels, nlevels, nchunk);
16541654
}
16551655

1656+
/* The following will not normally be called. It is experimental,
1657+
and intended for future debugging. It may go away at any time.
1658+
*/
1659+
static PyObject *
1660+
Cntr_get_cdata(Cntr *self)
1661+
{
1662+
PyArrayObject *Cdata;
1663+
npy_intp dims[2];
1664+
int i, j;
1665+
int ni, nj;
1666+
1667+
dims[0] = ni = self->site->imax;
1668+
dims[1] = nj = self->site->jmax;
1669+
1670+
Cdata = (PyArrayObject *) PyArray_SimpleNew(2, dims, PyArray_SHORT);
1671+
for (j=0; j<nj; j++)
1672+
for (i=0; i<ni; i++)
1673+
Cdata->data[j + i*nj] = self->site->data[i + j*ni];
1674+
/* output is C-order, input is F-order */
1675+
/* for now we are ignoring the last ni+1 values */
1676+
return (PyObject *)Cdata;
1677+
}
1678+
16561679
static PyMethodDef Cntr_methods[] = {
16571680
{"trace", (PyCFunction)Cntr_trace, METH_VARARGS | METH_KEYWORDS,
16581681
"Return a list of contour line segments or polygons.\n\n"
@@ -1665,6 +1688,12 @@ static PyMethodDef Cntr_methods[] = {
16651688
" Optional argument: nchunk; approximate number of grid points\n"
16661689
" per chunk. 0 (default) for no chunking.\n"
16671690
},
1691+
{"get_cdata", (PyCFunction)Cntr_get_cdata, METH_NOARGS,
1692+
"Returns a copy of the mesh array with contour calculation codes.\n\n"
1693+
"Experimental and incomplete; we are not returning quite all of\n"
1694+
"the array.\n"
1695+
"Don't call this unless you are exploring the dark recesses of cntr.c\n"
1696+
},
16681697
{0, 0, 0, 0} /* Sentinel */
16691698
};
16701699

0 commit comments

Comments
 (0)