Duplicate Ticks

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.
http://old.nabble.com/file/p34004789/duplicate_ticks.py duplicate_ticks.py
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.

···

--
View this message in context: http://old.nabble.com/Duplicate-Ticks-tp34004789p34004789.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I'm sorry, there seems to be a mess. Nabble told me that this mail to the
list was not accepted for unknown reasons so I deleted it. Here is the
example I was talking about in the previous mail:

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)

···

--
View this message in context: http://old.nabble.com/Duplicate-Ticks-tp34005378p34005490.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

This is my output using v1.1.1-rc2

X-Axis
tick @ (1.0, 0.0)
tick @ (0.0, 1.0)
Y-Axis
1.0 @ (0.0, 1.0)
1.0 @ (1.0, 0.0)
1.5 @ (0.0, 1.5)

1.5 @ (1.0, 0.0)
2.0 @ (0.0, 2.0)
2.0 @ (1.0, 0.0)
2.5 @ (0.0, 2.5)
2.5 @ (1.0, 0.0)
3.0 @ (0.0, 3.0)
3.0 @ (1.0, 0.0)

Strange indeed.

Ben Root

···

On Wed, Jun 13, 2012 at 10:46 AM, Peter Würtz <pwuertz@…982…> wrote:

I’m sorry, there seems to be a mess. Nabble told me that this mail to the

list was not accepted for unknown reasons so I deleted it. Here is the

example I was talking about in the previous mail:

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)

Benjamin Root-2 wrote:

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)

This is my output using v1.1.1-rc2

X-Axis
tick @ (1.0, 0.0)
tick @ (0.0, 1.0)

Strange indeed.

So, it is a bug then? Doesn't look like a feature to me :slight_smile:

···

On Wed, Jun 13, 2012 at 10:46 AM, Peter Würtz > <pwuertz@...982...>wrote:

--
View this message in context: http://old.nabble.com/Duplicate-Ticks-tp34005378p34015581.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

The reason it is happening is that Tick is a complicated beast, and it always includes two Text objects, whether they are needed or not. Whether they are drawn is controlled by the attributes 'label1On' and 'label2On', not by the standard Artist.get_visible(). I don't see any reason offhand why it couldn't be modified to use get_visible().

Eric

···

On 06/14/2012 02:39 PM, Peter Würtz wrote:

Benjamin Root-2 wrote:

On Wed, Jun 13, 2012 at 10:46 AM, Peter Würtz >> <pwuertz@...982...>wrote:

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)

This is my output using v1.1.1-rc2

X-Axis
  tick @ (1.0, 0.0)
  tick @ (0.0, 1.0)

  Strange indeed.

So, it is a bug then? Doesn't look like a feature to me :slight_smile: