I am trying to change the underlying data for my plot via a pick event,
except that the matplotlib examples for picking show a couple of functions
with predefined signatures and I can't seem to figure out how to modify my
data from within those functions...how to do it?
Here is a minimal example of what I am trying to do:
[code]
import matplotlib.pyplot as plt
def pick_rlines(art,mouseevent):
button = mouseevent.button
key = mouseevent.key
wsf.nnn = 4 # <-- how to modify wsf.nnn from here?
print "wsf.nnn = ", wsf.nnn
props = dict(nnn=wsf.nnn)
return True, props
def pick_handler(event):
mouseevent = event.mouseevent
button = mouseevent.button
key = mouseevent.key
art = event.artist
wsf.nnn = event.nnn # <-- or from here ?
class AAA():
pass
class BBB():
def __init__(self):
pass
wsf=AAA() # when it is defined here?
wsf.nnn=0
GR = [1.0, 2.0, 3.0, 4.0]
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.75,0.75])
ax.set_aspect(1)
rlines = ax.hlines(GR,0.0,4.0,picker=pick_rlines)
fig.canvas.mpl_connect('pick_event', pick_handler)
plt.show()
if __name__ == '__main__':
the = BBB()
[/code]
thanks in advance for any pointers.
···
--
View this message in context: http://old.nabble.com/access-to-my-underlying-data-from-within-picker-or-pick_handler-tp33492013p33492013.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
In the code as you’ve written it, “the” is in the global namespace, and so your pick event handlers can see that variable. So you could write:
def pick_rlines(art,mouseevent):
button = mouseevent.button
key = mouseevent.key
the.wsf.nnn = 4 # “the” is in the global namespace
But a cleaner design would be to make the pick handler a class method of class “BBB”, eg
class BBB:
def init(self):
self.fig = blah_blah…
self.fig.canvas.mpl_connect(‘pick_event’, self.pick_handler)
self.wsf = blah_blah…
def pick_handler(self, artist, event):
self.wsf.nnn = 4 # wsf is in the class namespace
···
On Mon, Mar 12, 2012 at 11:05 PM, gsal <salgerman@…1003…7…> wrote:
I am trying to change the underlying data for my plot via a pick event,
except that the matplotlib examples for picking show a couple of functions
with predefined signatures and I can’t seem to figure out how to modify my
data from within those functions…how to do it?
Here is a minimal example of what I am trying to do:
[code]
import matplotlib.pyplot as plt
def pick_rlines(art,mouseevent):
button = mouseevent.button
key = mouseevent.key
wsf.nnn = 4 # ← how to modify wsf.nnn from here?
print "wsf.nnn = ", wsf.nnn
props = dict(nnn=wsf.nnn)
return True, props
def pick_handler(event):
mouseevent = event.mouseevent
button = mouseevent.button
key = mouseevent.key
art = event.artist
wsf.nnn = event.nnn # ← or from here ?
class AAA():
pass
class BBB():
def init(self):
pass
wsf=AAA() # when it is defined here?
wsf.nnn=0
GR = [1.0, 2.0, 3.0, 4.0]
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.75,0.75])
ax.set_aspect(1)
rlines = ax.hlines(GR,0.0,4.0,picker=pick_rlines)
fig.canvas.mpl_connect(‘pick_event’, pick_handler)
plt.show()
if name == ‘main’:
the = BBB()
Thanks. That did the trick.
···
--
View this message in context: http://old.nabble.com/access-to-my-underlying-data-from-within-picker-or-pick_handler-tp33492013p33494708.html
Sent from the matplotlib - users mailing list archive at Nabble.com.