On Fri, Mar 23, 2012 at 3:35 PM, Andrew Smart <andrew.johnsm...@gmail.com>wrote:
> Hi,
> I'm running into this RuntimeError: Could not open facefile
> c:\Python32\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf;
> Cannot_Open_Resource when I'm trying to save out a series of *.png files in
> a loop. It crashes on this error after many passes through the loop and
> successful files get created, but then always on the same pass it does
> this. The full traceback is here:
>
> I wonder if the solution is as simple as doing font caching at the class
level rather than instance level. Andrew, could you try editing
matplotlib/backends/backend_agg.py and replace
class RendererAgg(RendererBase):
"""
The renderer handles all the drawing primitives using a graphics
context instance that controls the colors/styles
"""
debug=1
def __init__(self, width, height, dpi):
if __debug__: verbose.report('RendererAgg.__init__',
'debug-annoying')
RendererBase.__init__(self)
self.texd = maxdict(50) # a cache of tex image rasters
self._fontd = maxdict(50)
with
class RendererAgg(RendererBase):
"""
The renderer handles all the drawing primitives using a graphics
context instance that controls the colors/styles
"""
debug=1
_fontd = maxdict(50)
texd = maxdict(50) # a cache of tex image rasters
def __init__(self, width, height, dpi):
if __debug__: verbose.report('RendererAgg.__init__',
'debug-annoying')
RendererBase.__init__(self)
Does anyone see an issue with doing this caching at the class level? If
this works, we should have *many* fewer font files parsed.
w/o modifying the src code, a related way to test this idea is to reuse the
same figure instance and clear it at the start of the loop. Ie, rather than
for i in range(N):
fig = plt.figure()
....plot_something
fig.savefig(...)
do
fig = plt.figure()
for i in range(N):
fig.clf()
....plot_something
fig.savefig(...)
I would try the latter first, and if that works I would appreciate it if
you test the src code modification unless someone chimes in and tells us
that is a really bad idea.
JDH
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users