Hello,

I'm searching for a way to extract all text elements from a matplotlib
figure including their positions, styles, alignments etc. I first
tried to write a custom backend and to fetch all the texts from the
"draw_text()" method of the renderer. In contrast to the documentation
"draw_text()" does not receive a matplotlib.text.Text instance with
all the necessary information but only a simple string and a
pre-layouted position.

So I found this "findobj" method to get all Text elements from a
figure in a list, which is exactly what I was looking for. However, I
get some weird duplicates for all the tick labels and I don't know how
to handle them.

This is a small example that uses findobj on the axis objects and
prints the texts.

import matplotlib
import pylab as p

p.plot([1,2,3])
p.xticks([1],["tick"])
ax = p.gca()
fig = p.gcf()

p.draw()
def print_texts(artist):
    for t in artist.findobj(matplotlib.text.Text):
        if t.get_visible() and t.get_text():
            print " %s @ %s" % (t.get_text(), t.get_position())

print "X-Axis"
print_texts(ax.xaxis)
print "Y-Axis"
print_texts(ax.yaxis)

On all my matplotlib installations, all tick labels have duplicates
positioned at the end of the axis. Why? How to filter them out from a
list of Text elements? Their get_visible() attribute is True.

Another thing is that I first had to do a "draw()" call in order to
have the ticks generated/updated at all. How do I force an update of
the tick labels. Colorbar seems to have a "update_ticks()" method, but
I can't find something similar for the axis ticks.

------------------------------------------------------------------------------
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

Reply via email to