can contour be drawed in "vector mode"?

Hi,
matplotlib can make a contour plot on a masked array z using
contourf(x,y,z).but it seems that it draws in a raster mode.there is
sawtooth at the edge of the picture when it is zoomed.can contour be
drawed in a vector mode? i means that
1) give an array z which has not been masked.
2) contourf
3) using a ploygon array as a mask instead of using a masked grid array.
the part out of the polygon will be clipped.it seems that cairo and agg can
both work in this way.

shu

···

--
<>

shuwj5460@...1221... wrote:

Hi,
matplotlib can make a contour plot on a masked array z using
contourf(x,y,z).but it seems that it draws in a raster mode.there is
sawtooth at the edge of the picture when it is zoomed.can contour be
drawed in a vector mode? i means that
1) give an array z which has not been masked.
2) contourf
3) using a ploygon array as a mask instead of using a masked grid array.
the part out of the polygon will be clipped.it seems that cairo and agg can
both work in this way.

contourf is not drawing in raster mode--it is generating filled polygons. What you are seeing is the fact that when it follows the edge of a masked region, it does so in a stairstep fashion. This is inherent in the algorithm being used. I have thought a little bit about ways of making it at least take a diagonal path when reasonable so as to reduce the jaggy effect. I am not at all sure it would be worth the trouble, though--I expect it would be a lot of work for only a little gain.

To get around this you may want to use some interpolation/extrapolation to extend your data one grid point into the masked region, then contour with the reduced masked region, then plot your own filled polygon on top of the contour plot to define the masked region more precisely to your taste.

Yes, I agree that this is a pain, and that the present contour/contourf routine is not ideal (although it is very clever and I suspect very fast). If you can find a better filled contour routine with a BSD-style license, or even a clear and complete description of a superior algorithm that could be implemented without running into copyright or patent problems, please point it out to us.

There is one interesting difference between the algorithm we use (taken from the gist package) and the one used by Matlab: ours generates polygons that enclose only a given level--polygons do not overlap--whereas Matlab's generates polygons that stack. As a result, ours is suitable for use with alpha blending, whereas Matlab's is not (last time I looked, anyway).

Eric

contourf is not drawing in raster mode--it is generating filled
polygons. What you are seeing is the fact that when it follows the edge
of a masked region, it does so in a stairstep fashion. This is inherent
in the algorithm being used.

it seems that the filled polygon is composed of a set of points in some
a contour and some points in the 'drawn' edge which offsets with the
real edge of a masked region.

I have thought a little bit about ways of
making it at least take a diagonal path when reasonable so as to reduce
the jaggy effect. I am not at all sure it would be worth the trouble,
though--I expect it would be a lot of work for only a little gain.

I do think that matplotlib can do a very good job now. the same time i
think it's valuable to take some time to work out this little flaw.
maybe there're some tricky methods.
1) make a contourf plot on the whole rectangle mesh with no mask.
2) make a mask picture of the same size with the contourf plot. black in
mask ploygon and white outside.
3) do AND operation on contourf plot and the mask picture and outside
the mask polygon will be clipped.

x,y is axes array.
z is mesh grid data array.
zz is mesh grid data array with mask.
p is polygon for the edge.

cs=contourf(x,y,z) ----> contourf plot,identifies A.
cs2=contour(x,y,zz)
clabel(cs2,....) --> label at the right position inside the mask polygon.
draw_polygon(p,fillcolor=black) --> make a mask picture of the same
                                          size with A,identifies B.
A and B drawing. ---> it seems that cairo and agg can do this.
                        i don't know how to do in matplotlib.but i'm
                        sure some functions work for it.

there's no need to change the mask array when we zoom the picture now
because the mask picture is redrawn dynamicaly and 'vectorly'
.

To get around this you may want to use some interpolation/extrapolation
to extend your data one grid point into the masked region, then contour
with the reduced masked region, then plot your own filled polygon on top
of the contour plot to define the masked region more precisely to your
taste.

yes,filled contour map with smooth edge can be drawn with a more high
resolution mask array given.it's not a hard job.However,there's some
disadvantages in this way.firstly,mask array will have much larger size
than before and x,y arrays will be enlarged.these steps should be
repeated every time we wanna zoom the picture.

Yes, I agree that this is a pain, and that the present contour/contourf
routine is not ideal (although it is very clever and I suspect very
fast). If you can find a better filled contour routine with a BSD-style
license, or even a clear and complete description of a superior
algorithm that could be implemented without running into copyright or
patent problems, please point it out to us.

There is one interesting difference between the algorithm we use (taken
from the gist package) and the one used by Matlab: ours generates
polygons that enclose only a given level--polygons do not
overlap--whereas Matlab's generates polygons that stack. As a result,
ours is suitable for use with alpha blending, whereas Matlab's is not
(last time I looked, anyway).

Eric

would you like to add some more interpolation algorithm such as kriging
ect.to matplotlib? there are many interpolation source codes in public.

shu

···

--
<>