eps/pdf/svg contourf contours don't overlap properly with high resolution data

Jordan Dawe <jdawe@...128...> writes:

Contourf plots that I output in vector format files have little
triangular glitches at the contour boundaries if the contoured array
is larger than about 200x200. The same files in png format are
perfect, even at very high dpi values.

The current svn trunk doesn't have the really jarring little triangles
(at least in the pdf output), but there are still several very obtuse
white triangles between the regions. Rasterization at a high dpi makes
the output somewhat better at the cost of larger output files:

c=contourf(X, Y, Z, 10)
axis((-3, 3, -3, 3))
savefig('unrasterized.pdf')
for d in c.collections:
    d.set_rasterized(True)
savefig('rasterized.pdf',dpi=200)

unrasterized.pdf (12.8 KB)

rasterized.pdf (70 KB)

Jouni K. Seppänen wrote:

Jordan Dawe <jdawe@...128...> writes:

Contourf plots that I output in vector format files have little
triangular glitches at the contour boundaries if the contoured array
is larger than about 200x200. The same files in png format are
perfect, even at very high dpi values.

The current svn trunk doesn't have the really jarring little triangles
(at least in the pdf output), but there are still several very obtuse
white triangles between the regions. Rasterization at a high dpi makes
the output somewhat better at the cost of larger output files:

c=contourf(X, Y, Z, 10)
axis((-3, 3, -3, 3))
savefig('unrasterized.pdf')
for d in c.collections:
    d.set_rasterized(True)
savefig('rasterized.pdf',dpi=200)

At least in the trunk--and maybe in 0.99.0--the problem is caused by path simplification. In the trunk, for the eps file, it goes away completely if I use a matplotlibrc with

path.simplify : False

In the trunk, what seems to be happening is that when a contour boundary is almost straight, but has an inflection point, the curves for the adjacent patch boundaries are simplified slightly differently. This is not surprising; if nothing else, the path will be traveled in a different direction when it is an outer boundary than when it is an inner boundary (for a set of concentric boundaries).

Jordan, try using a local matplotlibrc with the above. Unless you are already customizing via a local matplotlibrc, that line is all you need.

One reason the trunk behavior differs from 0.99.0 is that contour patch boundaries are now being turned into compound boundaries instead of using a branch cut to connect the outside path to the inside path. I suspect simplification is causing the artifacts in both cases, though.

Eric

This is actually revealing a secondary bug. It is a bug that filled objects are being simplified at all. For various reasons, the simplification algorithm is not safe for use with filled regions (mainly because it doesn't ensure the end points match up). The Agg backend turns simplification off for filled objects, but the PDF, PS and SVG backends were not doing this. I've committed a fix to the branch and trunk, so in the future, this "path.simplify: False" workaround for contours should not be necessary.

Mike

Eric Firing wrote:

···

Jouni K. Sepp�nen wrote:

Jordan Dawe <jdawe@...128...> writes:

Contourf plots that I output in vector format files have little
triangular glitches at the contour boundaries if the contoured array
is larger than about 200x200. The same files in png format are
perfect, even at very high dpi values.

The current svn trunk doesn't have the really jarring little triangles
(at least in the pdf output), but there are still several very obtuse
white triangles between the regions. Rasterization at a high dpi makes
the output somewhat better at the cost of larger output files:

c=contourf(X, Y, Z, 10)
axis((-3, 3, -3, 3))
savefig('unrasterized.pdf')
for d in c.collections:
    d.set_rasterized(True)
savefig('rasterized.pdf',dpi=200)

At least in the trunk--and maybe in 0.99.0--the problem is caused by path simplification. In the trunk, for the eps file, it goes away completely if I use a matplotlibrc with

path.simplify : False

In the trunk, what seems to be happening is that when a contour boundary is almost straight, but has an inflection point, the curves for the adjacent patch boundaries are simplified slightly differently. This is not surprising; if nothing else, the path will be traveled in a different direction when it is an outer boundary than when it is an inner boundary (for a set of concentric boundaries).

Jordan, try using a local matplotlibrc with the above. Unless you are already customizing via a local matplotlibrc, that line is all you need.

One reason the trunk behavior differs from 0.99.0 is that contour patch boundaries are now being turned into compound boundaries instead of using a branch cut to connect the outside path to the inside path. I suspect simplification is causing the artifacts in both cases, though.

Eric

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Yes, it's true that uncommenting path.simplify : False line inside the
matplotlibrc file fixes the artifacts. However, it also produces HUGE
PDF/EPS file sizes. Perhaps, it's better to change path.simplify parameter
as needed inside the code via:

import matplotlib.pyplot as plt
plt.rcParams['path.simplify'] = False
# Plotting Code Block goes here
plt.rcdefaults()

Does anyone have another fix for this problem that DOES NOT produce HUGE
PDF/EPS files?

efiring wrote:

···

Jouni K. Seppänen wrote:

Jordan Dawe <jdawe@...128...> writes:

Contourf plots that I output in vector format files have little
triangular glitches at the contour boundaries if the contoured array
is larger than about 200x200. The same files in png format are
perfect, even at very high dpi values.

The current svn trunk doesn't have the really jarring little triangles
(at least in the pdf output), but there are still several very obtuse
white triangles between the regions. Rasterization at a high dpi makes
the output somewhat better at the cost of larger output files:

c=contourf(X, Y, Z, 10)
axis((-3, 3, -3, 3))
savefig('unrasterized.pdf')
for d in c.collections:
    d.set_rasterized(True)
savefig('rasterized.pdf',dpi=200)

At least in the trunk--and maybe in 0.99.0--the problem is caused by
path simplification. In the trunk, for the eps file, it goes away
completely if I use a matplotlibrc with

path.simplify : False

In the trunk, what seems to be happening is that when a contour boundary
is almost straight, but has an inflection point, the curves for the
adjacent patch boundaries are simplified slightly differently. This is
not surprising; if nothing else, the path will be traveled in a
different direction when it is an outer boundary than when it is an
inner boundary (for a set of concentric boundaries).

Jordan, try using a local matplotlibrc with the above. Unless you are
already customizing via a local matplotlibrc, that line is all you need.

One reason the trunk behavior differs from 0.99.0 is that contour patch
boundaries are now being turned into compound boundaries instead of
using a branch cut to connect the outside path to the inside path. I
suspect simplification is causing the artifacts in both cases, though.

Eric

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and
easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://old.nabble.com/eps-pdf-svg-contourf-contours-don't-overlap-properly-with-high-resolution-data-tp26982883p28617537.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I believe that the latest SVN revision should allow you to set rasterized=True for the call to contourf. I don’t know if the relevant code has been checked in or not. This should help with producing pdf files (and theoretically, eps files, although that backend might need some more work…).

Ben Root

···

On Thu, May 20, 2010 at 1:06 AM, ayuffa <ayuffa@…287…> wrote:

Does anyone have another fix for this problem that DOES NOT produce HUGE

PDF/EPS files?

    Does anyone have another fix for this problem that DOES NOT produce HUGE
    PDF/EPS files?

I believe that the latest SVN revision should allow you to set
rasterized=True for the call to contourf. I don't know if the relevant
code has been checked in or not. This should help with producing pdf
files (and theoretically, eps files, although that backend might need
some more work...).

The OP's problem is caused by a path simplification bug that is fixed in svn, so if the OP can build mpl from svn, then there is no need to turn on rasterization.

Eric

···

On 05/24/2010 04:55 AM, Benjamin Root wrote:

On Thu, May 20, 2010 at 1:06 AM, ayuffa <ayuffa@…287… > <mailto:ayuffa@…287…>> wrote:

Ben Root

------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users