SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: Patrik S. <pat...@ne...> - 2004年09月22日 08:06:56
Hi there,
matplotlib.text.Text._get_layout(self, renderer) caches
its return value in the dictionary matplotlib.text.Text.cached.
Since it is never emptied, it causes problems when one
creates many figures.
Below, t0.png is ok but t1.png has the vertical tick label 0 in the
wrong place.
import matplotlib
matplotlib.use('Agg')
from matplotlib.matlab import *
y = [[100, 250], [10, 25]]
for i in range(2):
 figure(1)
 bar([0,1], y[i])
 savefig('t%d.png' % i)
 # Uncomment to fix
 #matplotlib.text.Text.cached = {}
 close('all')
-- 
Patrik
From: Patrik S. <pat...@ne...> - 2004年09月22日 12:49:23
Attachments: text.py.diff
Here's a proposed patch for the caching problem in text.py.
(I'm sending it before someone actually adds
matplotlib.text.Text.cached = {}
to, e.g., matlab.close(). Oh, the horror :-)
-- 
Patrik
From: John H. <jdh...@ac...> - 2004年09月22日 13:03:51
>>>>> "Patrik" == Patrik Simons <pat...@ne...> writes:
 Patrik> Here's a proposed patch for the caching problem in
 Patrik> text.py. (I'm sending it before someone actually adds
 Patrik> matplotlib.text.Text.cached = {} to, e.g.,
 Patrik> matlab.close(). Oh, the horror :-)
What happened when you put it there?
It's not clear to me where to me where that misplaced zero is coming
from. Since the two figures are identical in size, I would think the
cached location of '0' from the first iteration of the loop would be
suitable for the second iteration. Do you understand how this is
failing?
The main reason for the cache was for efficiency in animated plots.
Eg, if you are just updating the data in a plot and then redrawing,
you don't want to do all the number crunching for text layout. With
rotated text and matrix operations to get the layout right, this can
get expensive.
I read over your patch. I wonder if a simpler and cleaner solution
might just be to move the cached into the __init__ method. Ie, make
it instance specific. This would still provide the cache efficiency
for animated plots, but should fix the problem you encountered.
It might also be less mind-bending than the solution you posted, at
least at this hour of the morning :-)
But I *would* like to understand how the current situation is
failing. I note that it does not occur if you replace figure(1) with
figure(i+1).
JDH
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /