On 2012/09/03 1:38 AM, Jakob Gager wrote: > Recently, I switched from matplotlib 0.99 to 1.0.1 and unfortunately > discovered > that my text scaling script stopped working properly. The script scales the > given text > to fit into the current figure. > > A quick example of what I'm doing (works in 0.99, but not in 1.0.1 and > 1.1.1rc): > import matplotlib.pyplot as plt > plt.ion() > fig = plt.figure(1, (6,8), dpi=72) > fig.add_axes([0,0,1,1]) > txt1 = > plt.text(0.5,0.5,'foobar',horizontalalignment='center',verticalalignment='center') > plt.draw() > # compute width of figure in points and divide by txt1 bounding box width > sf1 = 6*72./txt1.cached.items()[0][1][1][0][1][0] > txt1.set_size(txt1.get_size()*sf1) > plt.draw() > > The problem is related to the fact that starting from mpl 1.0.1, the > txt1.cached dictionary contains > information of all text objects present rather than only of the specific > object. > I guess this behavior is intended, however this way it is rather complicated > to derive the bounding > box of the specific text object without cycling over the whole dictionary.
It looks like you can either use the _get_layout() method (which requires that you specify the renderer), or, if you know the text object will be among the last 50 for which _get_layout() has been called, you can use txt1.cached[txt1.get_prop_typ()]. > > Is there a different way to achieve a fitted text object? Not that I know of; but someone else may have a suggestion. Eric > > Thanks, > br Jakob > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users