Unavoidable gridlines in pcolor pdf output

Benjamin Root <ben.root@...553...> writes:

It seems that savig a pcolor plot to a pdf format always includes
gridlines, which isn't true for other output formats like png. The
attached example demonstrates this problem. I've only tested this on
version 1.1.1rc1.

I have reported something like this before, and it seems that it is
dependent upon the PDF viewer and i's settings. Particularly, the
antialiasing settings. I have seen this with gs-based viewers. Have you
tried others?

I see gridlines in the resulting image in gs, xpdf Preview.app but not
in Adobe Reader. When I zoom in Preview, the lines jump around a bit,
and are always the same width on the screen regardless of zoom level.

What gets drawn in this example is a lot of polygons, so that adjacent
polygons share an edge with the exact same coordinates. The code fills
the inside of each polygon, and apparently some rendering algorithms
leave a minimal-width line between polygons.

Making the polygons overlap by one pdf unit (1/72 of an inch) seems to
make the lines go away at least in Preview. Making them overlap by 0.1
units does not help.

I don't think this can be fixed purely in the pdf backend; it just gets
a path collection and draws each polygon. I suppose pcolor would need to
pad the polygons a little, but could it cause problems with other
backends or use cases? (E.g. if you use alpha blending, neighboring
rectangles might get gridlines of a darker color where they overlap.)

I wonder if drawing zero-width lines between neighboring rectangles,
e.g. taking the color always from the left or the upper rectangle, would
work. In matplotlib a line of zero width means no line at all, but in
the pdf file format it means a line of the smallest possible width,
which might work well for filling in a missing line of that same
width. This would need some kind of special-casing in the graphics
context (because linewidth=0 means to not draw a line) so it's not
completely trivial to try it out.

A different approach would be to output a raster image from pcolor and
render it with large pixels. I don't know how well that would work with
Agg, though.

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks

Benjamin Root<ben.root@...553...> writes:

It seems that savig a pcolor plot to a pdf format always includes
gridlines, which isn't true for other output formats like png. The
attached example demonstrates this problem. I've only tested this on
version 1.1.1rc1.

I have reported something like this before, and it seems that it is
dependent upon the PDF viewer and i's settings. Particularly, the
antialiasing settings. I have seen this with gs-based viewers. Have you
tried others?

I see gridlines in the resulting image in gs, xpdf Preview.app but not
in Adobe Reader. When I zoom in Preview, the lines jump around a bit,
and are always the same width on the screen regardless of zoom level.

What gets drawn in this example is a lot of polygons, so that adjacent
polygons share an edge with the exact same coordinates. The code fills
the inside of each polygon, and apparently some rendering algorithms
leave a minimal-width line between polygons.

Making the polygons overlap by one pdf unit (1/72 of an inch) seems to
make the lines go away at least in Preview. Making them overlap by 0.1
units does not help.

Does it make them go away with alpha = 0.5, say?

I don't think this can be fixed purely in the pdf backend; it just gets
a path collection and draws each polygon. I suppose pcolor would need to
pad the polygons a little, but could it cause problems with other
backends or use cases? (E.g. if you use alpha blending, neighboring
rectangles might get gridlines of a darker color where they overlap.)

I'm very skeptical about attempted workarounds such as padding; I would be amazed if any of them work over the full range of cases--backends, alpha, antialiasing, viewers--while maintaining accuracy of plot element placement.

Has cairo solved this problem? Anyone else?

I wonder if drawing zero-width lines between neighboring rectangles,
e.g. taking the color always from the left or the upper rectangle, would
work. In matplotlib a line of zero width means no line at all, but in
the pdf file format it means a line of the smallest possible width,
which might work well for filling in a missing line of that same
width. This would need some kind of special-casing in the graphics
context (because linewidth=0 means to not draw a line) so it's not
completely trivial to try it out.

Problems occur not just with rectangles but with all patch boundaries, such as in contourf. The problem may be most severe with rectangles, though.

We have gone around in circles with this problem before.

A different approach would be to output a raster image from pcolor and
render it with large pixels. I don't know how well that would work with
Agg, though.

I don't understand; wouldn't this wreck accuracy and defeat the purpose of using pdf (scalability)?

Eric

···

On 04/09/2012 04:13 AM, Jouni K. Seppänen wrote:

Setting alpha 0.5 didn't help. It made the contours more transparent
as expected, but the unwanted lines remain yet with the same amount of
transparency.

Best wishes,
Mike

···

On Mon, Apr 9, 2012 at 1:43 PM, Eric Firing <efiring@...229...> wrote:

Making the polygons overlap by one pdf unit (1/72 of an inch) seems to
make the lines go away at least in Preview. Making them overlap by 0.1
units does not help.

Does it make them go away with alpha = 0.5, say?

Making the polygons overlap by one pdf unit (1/72 of an inch) seems to
make the lines go away at least in Preview. Making them overlap by 0.1
units does not help.

Does it make them go away with alpha = 0.5, say?

Setting alpha 0.5 didn't help. It made the contours more transparent
as expected, but the unwanted lines remain yet with the same amount of
transparency.

Sorry, my point was that even if the 1/72 overlap "works" with some viewers with alpha = 1, I would expect it to cause trouble with non-unit alpha, with some if not with all viewers. I don't think there is any hack that works in general, and a 1/72 overlap sounds to me like a hack.

Eric

···

On 04/09/2012 09:25 AM, Michael Gilbert wrote:

On Mon, Apr 9, 2012 at 1:43 PM, Eric Firing<efiring@...229...> wrote:

Best wishes,
Mike

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel