Repeated calls to set_text using TeX formatting results in RuntimeError
I’m doing a parameter fitting exercise, and plotting the progress as I do so. I have found that repeated calls to set_text() on a text object will result in an error opening a font file iff the text uses TeX formatting. (I am not using the experimental usetex feature).
I speculate that matplotlib is opening the font file anew with each call to set_text and never closing it, resulting ultimately in having too many files open. Here is a brief program to reproduce this behavior (WinXP, Py2.5, matplotlib 0.90.1):
from pylab import figure, axes, draw, ion
from numpy import array, cos, abs
ion()
fig=figure()
axs=axes()
x=array(range(100))/10.0
cosPlot=axs.plot( x, cos(x)**2, ‘r’ )
powText = axs.text(0.9,0.02,r’$\alpha=$’,
horizontalalignment='left',verticalalignment='bottom',
transform = axs.transAxes)
draw()
for alpha in array(range(10,400))/100.0:
axs.lines[-1].set_ydata( abs(cos(x))**alpha)
powText.set_text(r'$\alpha=%.4g$'%alpha)
print alpha
draw()
Traceback (most recent call last):
File “delme.py”, line 16, in
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\pylab.py”, line 754, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\backends\backend_tkagg.py”, line 154, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\backends\backend_agg.py”, line 392, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\figure.py”, line 601, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\axes.py”, line 1286, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\text.py”, line 410, in draw
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\text.py”, line 255, in _get_layout
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\backends\backend_agg.py”, line 246, in get_text_width_height
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\mathtext.py”, line 1569, in call
File “C:\Python25\Lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\mathtext.py”, line 578, in init
RuntimeError: Could not open facefile c:\Python25\lib\site-packages\matplotlib-0.90.1-py2.5-win32.egg\matplotlib\mpl-data\fonts\ttf\cmtt10.ttf; Cannot_Open_Resource
disclaim.txt (931 Bytes)