Toggling country boundaries in MPL Basemap

Mauro Cavalcanti wrote:

Dear Jeff,

Sorry, I then got a TypeError: remove() takes exactly one argument (0
given)... :frowning:

Best regards,
  
Mauro: Don't know why that would be. Here's what I get

% ipython --pylab

In [3] from mpl_toolkits.basemap import Basemap

In [4]: m = Basemap()

In [5]: c = m.drawcountries() # map pops up with country boundaries drawn

In [6]: type(c)
Out[6]: <class 'matplotlib.collections.LineCollection'>

In [7]: help(c.remove)
Help on method remove in module matplotlib.artist:

remove(self) method of matplotlib.collections.LineCollection instance
    Remove the artist from the figure if possible. The effect
    will not be visible until the figure is redrawn, e.g., with
    :meth:`matplotlib.axes.Axes.draw_idle`. Call
    :meth:`matplotlib.axes.Axes.relim` to update the axes limits
    if desired.

In [8]: c.remove()

In [9]: draw() # countries disappear from map.

-Jeff

···

2008/12/5 Jeff Whitaker <jswhit@...146...>:
  

Mauro Cavalcanti wrote:
    

Dear Jeff,

Thanks for your fast reply. Unfortunately, I have not been able to get
yet working:

I have a menu event like this:

borders = []
if self.MapDrawBorderItem.IsChecked():
       borders = self.map.drawcountries()
else:
       self.ax.lines.remove(borders)
      # .... redraw the map here...

But I got a ValueError: list.remove(x): x not in list

Any hints?

Mauro: Instead of

self.ax.lines.remove(borders)

I think should simply do

borders.remove()

-Jeff
    

With best regards,

2008/12/5 Jeff Whitaker <jswhit@...146...>:

Mauro Cavalcanti wrote:

Dear ALL,

Always engaged in pushing MPL/Basemap ahead of its limits, here am I
again with a humble question: I want to be able to toggle the display
of country boundaries on a map using a menu option on my wxPython
interface. It is quite easy to initially plotting a map without
borders and then toggling them on, but I could not figure out a way to
toggling them off (if possible, without redrawing the whole map). Is
there any trick to do this? :wink:

Thanks in advance!

With warmest regards,

Mauro:

The drawcountries() method returns a matplotlib line collection.
Invoking
the remove() method of the line collection will remove the countries from
the axes instance.

-Jeff

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg