plotting labels for each 'artist' in a basemap

Hello, using matplotlib 0.98 with mpl_toolkit Basemap:

I'm trying to create a plot with a series of ellipses over a map. I've
followed the tutorial, and can create the same figure as shown here:
http://matplotlib.sourceforge.net/users/screenshots.html#ellipses

I can also create a series of ellipses over a map.

Now I am trying to label each circle using the following snippet:
for item in ells:
    #ells is now a tuple in the form: (Ellipse, (x,y)) and (x,y) is the same
as for the Ellipse
     e = item[0]
     xy = item[1]
     ax.add_artist(e)
     e.set_clip_box(ax.bbox)
     e.set_alpha(.7)
     pyplot.text(xy[0],xy[1],e.get_label())

however, for some reason it fails. Can someone provide some ideas on what I
am doing wrong? Also, is there more direct way to set the plots so that the
labels are drawn?

What is strange, is that it seems to work (at least debugging print
statements after the loop are printed)... and I can move the text function
out of the loop to label the 'last' ellipse...

As it is it fails when savefig() or show() are called. The error is:
TypeError: CXX : Error creating object of type N2Py3IntE

THoughts?

Thanks,
john

···

--
View this message in context: http://www.nabble.com/plotting-labels-for-each-'artist'-in-a-basemap-tp20494609p20494609.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I just saw a similar error when trying to plot some text; in my case,
basemap wasn't involved.

The full error dump:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/text.py
in draw(self, renderer)
    486
--> 487 for line, wh, x, y in info:
    488 x = x + posx
    489 y = y + posy

TypeError: CXX : Error creating object of type N2Py3IntE

My x data were times in seconds calculated relative to a reference
date, and reducing the gap cleared up my problem.

This thread:
http://markmail.org/message/zqfgrshmq3366mtz?q=Error+N2Py3IntE
suggests that the error is due to an overflow in the underlying numerics.

And ... this is where I reach the end of my expertise.

-Eric

···

On Thu, Nov 13, 2008 at 11:38 PM, John [H2O] <washakie@...287...> wrote:

Hello, using matplotlib 0.98 with mpl_toolkit Basemap:

I'm trying to create a plot with a series of ellipses over a map. I've
followed the tutorial, and can create the same figure as shown here:
http://matplotlib.sourceforge.net/users/screenshots.html#ellipses

I can also create a series of ellipses over a map.

Now I am trying to label each circle using the following snippet:
for item in ells:
   #ells is now a tuple in the form: (Ellipse, (x,y)) and (x,y) is the same
as for the Ellipse
    e = item[0]
    xy = item[1]
    ax.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_alpha(.7)
    pyplot.text(xy[0],xy[1],e.get_label())

however, for some reason it fails. Can someone provide some ideas on what I
am doing wrong? Also, is there more direct way to set the plots so that the
labels are drawn?

What is strange, is that it seems to work (at least debugging print
statements after the loop are printed)... and I can move the text function
out of the loop to label the 'last' ellipse...

As it is it fails when savefig() or show() are called. The error is:
TypeError: CXX : Error creating object of type N2Py3IntE

THoughts?

Thanks,
john

--
View this message in context: http://www.nabble.com/plotting-labels-for-each-'artist'-in-a-basemap-tp20494609p20494609.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Can you post a complete, free-standing example script which replicates
the problem and also the output of the script run with
--verbose-debug? See

  http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem

JDH

···

On Thu, Nov 13, 2008 at 10:38 PM, John [H2O] <washakie@...287...> wrote:

Hello, using matplotlib 0.98 with mpl_toolkit Basemap:

I'm trying to create a plot with a series of ellipses over a map. I've
followed the tutorial, and can create the same figure as shown here:
http://matplotlib.sourceforge.net/users/screenshots.html#ellipses

I can also create a series of ellipses over a map.

Now I am trying to label each circle using the following snippet:
for item in ells:
   #ells is now a tuple in the form: (Ellipse, (x,y)) and (x,y) is the same
as for the Ellipse
    e = item[0]
    xy = item[1]
    ax.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_alpha(.7)
    pyplot.text(xy[0],xy[1],e.get_label())

however, for some reason it fails. Can someone provide some ideas on what I
am doing wrong? Also, is there more direct way to set the plots so that the
labels are drawn?

Can you post a complete, free-standing example script which replicates
the problem

import matplotlib.pyplot as plt
f=plt.figure()
ax=f.add_subplot(111)
ax.plot(range(10))
ax.text(-10, 5, 'this one is ok')
ax.text(-1202255993.82, 5, 'this one fails')
plt.show()

and also the output of the script run with --verbose-debug?

See attached.

Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007;
root:xnu-792.25.20~1/RELEASE_I386 i386 i386 (Mac OS X 10.4.11)

I'm running svn r6360 (with my draw_wrapper patch to handle per-artist
rasterizing)

mpl_debug.txt (8 KB)

Can you post a complete, free-standing example script which replicates
the problem

import matplotlib.pyplot as plt
f=plt.figure()
ax=f.add_subplot(111)
ax.plot(range(10))
ax.text(-10, 5, 'this one is ok')
ax.text(-1202255993.82, 5, 'this one fails')
plt.show()

and also the output of the script run with --verbose-debug?

See attached.

OK, thanks. I can replicate this on one machine (on which python is
compiled for 32bit)

  johnh@...1653...:~> uname -a
  SunOS flag 5.10 Generic_118855-15 i86pc i386 i86pc
  johnh@...1653...:~> python -V
  Python 2.4.5
  johnh@...1653...:~> gcc --version
  gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
  johnh@...1653...:~> python -c 'import sys; print sys.maxint'
  2147483647

but not on another (on which python supports 64 bit)

  jdhunter@...2404...:unit> uname -a
  Linux bic128.bic.berkeley.edu 2.6.26.6-49.fc8 #1 SMP Fri Oct 17
15:33:32 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
  jdhunter@...2404...:unit> python -V
  Python 2.5.1
  jdhunter@...2404...:unit> gcc --version
  gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)\
  jdhunter@...2404...:unit> python -c 'import sys; print sys.maxint'
  9223372036854775807

My guess is the transformation is putting this int out of bounds on
the 32 bit system triggering an exception in the cxx code.

From the exception, it looks like the exception is being set in cxx

extension code but is not being raised at the time the exception is
set, because there is no reason the iteration over the info should be
triggering the exception at that time. I fixed backend agg to raise
the proper exception so it is at least less confusing -- it now raises

johnh@...1653...:~> python test.py
Traceback (most recent call last):
  File "test.py", line 9, in ?
    fig.canvas.draw()
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 283, in draw
    self.figure.draw(self.renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/figure.py",
line 767, in draw
    for a in self.axes: a.draw(renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/axes.py",
line 1590, in draw
    a.draw(renderer)
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/text.py",
line 496, in draw
    ismath=self.is_math_text(line))
  File "/home/titan/johnh/dev/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 135, in draw_text
    self._renderer.draw_text_image(font.get_image(), int(x), int(y) +
1, angle, gc)
TypeError: Invalid input arguments to draw_text_image

I'm not sure what the desired behavior here is. We could make it fail
silently (not plot the text rather than raise)....

JDH

···

On Fri, Nov 21, 2008 at 10:37 AM, Eric Bruning <eric.bruning@...287...> wrote:

Can you post a complete, free-standing example script which replicates
the problem

import matplotlib.pyplot as plt
f=plt.figure()
ax=f.add_subplot(111)
ax.plot(range(10))
ax.text(-10, 5, 'this one is ok')
ax.text(-1202255993.82, 5, 'this one fails')
plt.show()

and also the output of the script run with --verbose-debug?

See attached.

OK, thanks. I can replicate this on one machine (on which python is
compiled for 32bit)

And I can confirm that my Python is running as 32 bit.

My guess is the transformation is putting this int out of bounds on
the 32 bit system triggering an exception in the cxx code.

From the exception, it looks like the exception is being set in cxx
extension code but is not being raised at the time the exception is
set, because there is no reason the iteration over the info should be
triggering the exception at that time. I fixed backend agg to raise
the proper exception so it is at least less confusing -- it now raises
...
TypeError: Invalid input arguments to draw_text_image

I'm not sure what the desired behavior here is. We could make it fail
silently (not plot the text rather than raise)....

My preference would be to see the error rather than mysteriously not
see text. The latter would be more frustrating to debug - hard to
track down. A scientific user should probably know that he's
overextending the floating point capability, which was my case.

I would be interested to see a concise form of John [H2O]'s bug,
though - it might get more subtle if it's doing something funny on a
map projection, like plotting on the backside of a sphere.

Thanks,
Eric

···

On Fri, Nov 21, 2008 at 12:24 PM, John Hunter <jdh2358@...287...> wrote:

On Fri, Nov 21, 2008 at 10:37 AM, Eric Bruning <eric.bruning@...287...> wrote:

Actually you are overflowing the int. In the backend, we transform
everything to pixel space, and the call fails when it tries to
initialize an int with the transformed coordinate.

JDH

···

On Fri, Nov 21, 2008 at 12:26 PM, Eric Bruning <eric.bruning@...287...> wrote:

My preference would be to see the error rather than mysteriously not
see text. The latter would be more frustrating to debug - hard to
track down. A scientific user should probably know that he's
overextending the floating point capability, which was my case.