Running it through gs (ghostscript) gives this error:

=====

GPL Ghostscript 8.70 (2009-07-31)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /stackoverflow in -file-
Operand stack:
    --nostringval--
Execution stack:
    %interp_exit   .runexec2   --nostringval--   --nostringval--   
--nostringval--   2   %stopped_push   --nostringval--   
--nostringval--   --nostringval--   false   1   %stopped_push   1846   
1   3   %oparray_pop   1845   1   3   %oparray_pop   --nostringval--   
1829   1   3   %oparray_pop   1723   1   3   %oparray_pop   
--nostringval--   %errorexec_pop   .runexec2   --nostringval--   
--nostringval--   --nostringval--   2   %stopped_push
Dictionary stack:
    --dict:1148/1684(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--   
--dict:7/8(L)--
Current allocation mode is local
Current file position is 675310
GPL Ghostscript 8.70: Unrecoverable error, exit code 1

=====

This indicates that the Postscript is running out of stack space 
(memory).  Indeed, the file has a very large path in it.

A little background: matplotlib includes an algorithm to "simplify" 
really long paths by removing points that don't actually contribute to 
the resulting image.  Unfortunately, this algorithm only works for 
unfilled paths -- dealing with the more general case of filled paths is 
more difficult.  That's why you only see this problem when using 
"fill_between" and not just when plotting lines.

The problem here is that it's hard to trap for this error -- the size of 
the Postscript stack is dependent on the Postscript interpreter being 
used, so what works in one place may not in another.

A simple way around this is to just decimate the data, i.e.:

   plt.plot(x[::5], pdf_min[::5], x[::5], pdf_max[::5], color="k")
   plt.fill_between(x[::5], pdf_min[::5], pdf_max[::5], color='0.85')

but obviously that's not doing anything terribly smart, so it won't work 
with all data.

Mike

On 05/13/2011 10:00 AM, Johannes Radinger wrote:
> Does anyone already know what causes the problem with the fill_between and 
> the eps output?
>
> /johannes
>
>
> -------- Original-Nachricht --------
>    
>> Datum: Thu, 12 May 2011 17:10:43 +0200
>> Von: Johannes Radinger<jradin...@gmx.at>
>> An: John Hunter<jdh2...@gmail.com>
>> CC: matplotlib-users@lists.sourceforge.net
>> Betreff: Re: [Matplotlib-users] eps output and fill_between
>>      
>    
>> Hello again,
>>
>> I tried the script you provided to test the PolyCollection and that works
>> fine.
>> I am working under Mac OS X 10.6.6 Snow Leopard and use matplotlib 1.0.1.
>>
>> That is the script where I fail with eps but not with pdf:
>>
>>
>>
>> import matplotlib.pyplot as plt
>> import numpy
>> from scipy import stats
>>
>> p=0.3
>> m=0
>> s1min=120
>> s1max=140
>> s2min=1200
>> s2max=1600
>>
>> x = numpy.arange((s2max*-1.5), (s2max*1.5), 0.2)
>>
>> def pdf(x,s1,s2):
>>      return p * stats.norm.pdf(x, loc=m, scale=s1) + (1-p) *
>> stats.norm.pdf(x, loc=m, scale=s2)
>>
>>
>> pdf_min = pdf(x,s1min,s2min)
>> pdf_max = pdf(x,s1max,s2max)
>>
>> plt.plot(x, pdf_min, x, pdf_max, color="k")
>> plt.fill_between(x, pdf_min, pdf_max, color='0.85')
>>
>>
>> #plt.show()
>> #plt.savefig("testplot.eps")
>> plt.savefig("testplot.pdf")
>>
>>
>> /Johannes
>>
>> Am 12.05.2011 um 15:28 schrieb John Hunter:
>>
>>      
>>>
>>> On Thu, May 12, 2011 at 3:42 AM, Johannes Radinger<jradin...@gmx.at>
>>>        
>> wrote:
>>      
>>> Hello ,
>>>
>>> sofar I know how to safe a plot into a *.eps file and it works good,
>>> but there is one issue with filled areas between two functions.
>>>
>>> When I try to use:
>>> plt.fill_between(x, pdf_min, pdf_max, color='0.85')
>>>
>>> and I try to open it on my mac I fail. So far as I know
>>> is the mac converting the eps internally to pdf to be
>>> displayed, but it seems it can't be converted.
>>>
>>> If I try to set the output to *.pdf it works perfectly and I can
>>> open the file. Something in the combination of fill_between
>>> and eps is causing the error. I tried also color="red" but with
>>> the same problems.
>>>
>>> Is there anything I've to set because I need the output as
>>> a working eps.
>>>
>>>
>>> under the hool, fill_between uses a PolyCollection.  Below is a simple
>>>        
>> example which uses a PolyCollection directly.  Does this crash when you
>> convert eps ->  pdf.  If not, maybe we can hone in on what is special about 
>> the
>> vertices in your fill_between example.  Also, you should give us some
>> information about what version of matplotlib and OSX you are running.
>>      
>>>
>>> import numpy as np
>>> import matplotlib.collections as mcollections
>>> import matplotlib.pyplot as plt
>>>
>>> theta = np.linspace(0, 2*np.pi, 20)
>>> x1 = np.cos(theta)
>>> y1 = np.sin(theta)
>>>
>>> x2 = x1 + 5
>>> y2 = y1 + 5
>>>
>>> verts1 = zip(x1, y1)
>>> verts2 = zip(x2, y2)
>>>
>>> c = mcollections.PolyCollection([verts1, verts2], facecolors=['red',
>>>        
>> 'green'])
>>      
>>> ax = plt.subplot(111)
>>> ax.add_collection(c)
>>> ax.axis([-5, 10, -5, 10])
>>>
>>> plt.savefig('test.eps')
>>> plt.show()
>>>
>>>        
>>      
>    


-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA


------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to