Hi All,
I hope someone can give me a simple solution to my problem. I have a line
plotted and I need to be able to mark selected data points on the line. I am
using the mpl_connect function to detect the mouseclick on the line and then
to place a marker at the selected datapoint. My data is 0.2s apart on a
1hour plot, so to click on a single data point i need to zoom into the
graph. Once I zoom in and select the data point, the marker doesn't appear
until the graph is resized or refreshed by the home button. Also, if I click
on an existing datapoint, is is removed in the array however when the graph
is redrawn or refreshed the marker is not deleted. Below is an exert of the
code. I am using embedded_wx4.py as a template. So the question is, how can
i show the marker at the zoomed level, it is apain to have to zoom out to
home view every time and why won't my redraw work. If there is any ambiguity
please let me know and I'll try to re-explain myself.
def _on_addmarker(self, evt): #defined from toolbar button
datamarker = self.canvas.mpl_connect('pick_event', self.onpick1)
evt.Skip()
def onpick1(self, event):
self.background_marker=self.canvas.copy_from_bbox(self.axes.bbox)
self.marker, = self.axes.plot(x,y, 'go',markersize=8)
if isinstance(event.artist, Line2D):
thisline=event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
tempx = xdata[ind]
tempy = ydata[ind]
print '------------'
print 'onpick1 line X:' ,tempx
print 'onpick1 line ind:' ,ind
print 'onpick1 line Y:' ,tempy
if xdata[ind] in x:
x.remove(tempx)
y.remove(tempy)
print '------------'
print 'you removed ' ,ind ,tempx ,tempy
print 'X=' ,x
print 'Y=' ,y
print '------------'
else:
x.append(tempx)
y.append(tempy)
print 'you clicked ' ,x ,y
print '------------'
time.sleep(0.1)
···
#-----------------------------------------------------------------------------------------
self.canvas.restore_region(self.background_marker)
self.marker.set_data(x,y)
self.axes.draw_artist(self.marker)
self.canvas.blit(self.axes.bbox)
and
class CanvasFrame(Frame):
global line, background
def __init__(self):
Frame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))
self.SetBackgroundColour(NamedColor("WHITE"))
self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
picker = 5
self.line, = self.axes.plot(cx,cy,picker=picker, linewidth=1)
etc..etc...
--
View this message in context: http://www.nabble.com/Plotting-single-marker-point-at-zoomed-level-tp17470649p17470649.html
Sent from the matplotlib - users mailing list archive at Nabble.com.