repaint subplot

Hi,

I am newbie using Matplotlib. I have to do an interactive application and before that, I am trying some tests to familiarize myself with the library.

I am plotting some 2d data together with 2 buttons. When one of the buttons is pressed, only a few points should be remain in the plot, and when the other button is pressed, all the initial points should be appear again. My problem is that when I press the first button, the points which sould be remain, change the colour (because I specify this), but the rest of the points also remain. How can I repaint again the plot to get what I want?

Thanks in advance

Here is the code (except the class Datos since it is not relevant for the plotting):

class eventos:

def __init__(self,datos, fig):
    self._datos = datos
    self._figure = fig

   
def pareto(self,event):
    tupla = self._datos.buscarDominados()
    sp=self._figure.add_subplot(111)
    sp.plot(tupla[0], tupla[1], 'o', color = 'yellow')


def todos(self,event):
    sp=self._figure.add_subplot(111)
    sp.plot(self._datos.darX(), self._datos.darY(), 'o', color = 'blue')

import datos
import matplotlib.pyplot as plt

from matplotlib.widgets import Button
import eventos

X = datos.datos()
X.randomNums(100)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(X.darX(), X.darY(), ‘o’)
boton = eventos.eventos(X, fig)

axbut = plt.axes([0.77, 0.02, 0.1, 0.05])
axbut2 = plt.axes([0.88, 0.02, 0.1, 0.05])
bpareto = Button(axbut, ‘Pareto’)
bnormal = Button(axbut2, ‘Todos’)
bpareto.on_clicked(boton.pareto)
bnormal.on_clicked(boton.todos)

plt.show()

W/o a complete free standing example that we can run, it is difficult
to see exactly what your problem is. If you post one, we can help you
more easily.

To answer some of your specific questions and point you to some solutions

* to cause a full figure redraw, do fig.canvas.draw(). You can
repaint portions of the canvase or selected artists using the
animation techniques described at
http://www.scipy.org/Cookbook/Matplotlib/Animations and
http://matplotlib.sourceforge.net/users/event_handling.html with
examples at http://matplotlib.sourceforge.net/examples/animation/index.html

* you can "remove" a line entirely if you don't want to plot it
anymore using the techniques described at
http://matplotlib.sourceforge.net/users/artists.html#artist-tutorial.
You can also temporarily make any artist invisible by setting
obj.set_visible(False)

* you can also control which points in an array are plotted by setting
a masked array, as in
http://matplotlib.sourceforge.net/examples/pylab_examples/masked_demo.html

Hope this helps,
JDH

···

On Wed, Feb 3, 2010 at 5:32 AM, Luis P. Guerra <luispelayo84@...287...> wrote:

Hi,

I am newbie using Matplotlib. I have to do an interactive application and
before that, I am trying some tests to familiarize myself with the library.

I am plotting some 2d data together with 2 buttons. When one of the buttons
is pressed, only a few points should be remain in the plot, and when the
other button is pressed, all the initial points should be appear again. My
problem is that when I press the first button, the points which sould be
remain, change the colour (because I specify this), but the rest of the
points also remain. How can I repaint again the plot to get what I want?