multiple lines in 1 graph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

multiple lines in 1 graph

stefanxfg
Hi, i have a matplotlib graph and i want to insert several lines or linesets to the graph. Until here no problem. I also want to see curser lines by adding onMouseMove-Event through 'motion_modify_event'-declaration. My problem is, that only the first drawn line is visible after mmoving the mouse on the graph. When the graph is only loaded, everything is visible, but by moving the mouse the second plot will be invisible. I dont know, whats the problem. THis is my code. def PlotInput(self): self.fig = Figure (figsize=(5,4), dpi=100) self.canvas = FigureCanvasTkAgg(self.fig,self) self.ax = self.fig.add_subplot(111) self.ax = self.fig.add_subplot(111) #fuer 2d-Plot self.ax.set_title('Definition der LRUGL') self.ax.set_xlabel('Breite y [mm]') self.ax.set_ylabel('Höhe z [mm]') self.ax.axis([-2000,2000,0, 5000]) self.ax.grid(True) self.toolbar = NavigationToolbar2TkAgg(self.canvas,self) self.toolbar.update() self.plot_widget = self.canvas.get_tk_widget() self.plot_widget.pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.toolbar.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=1) self.ax.plot(np.zeros(100)) def onMouseMove(event): self.ax.lines = [self.ax.lines[0]] if event.xdata and event.ydata: # python3 often has None self.ax.axhline(y=event.ydata, color="k") self.ax.axvline(x=event.xdata, color="k") self.fig.canvas.show() self.canvas.mpl_connect('motion_notify_event', onMouseMove) self.canvas.show() def fig_ax_request(x, y, x2): self.ax.clear() ya = np.array(x) za = np.array(y) yb = np.array(x2) self.ax.plot(yb,za, color='red', linestyle='--', marker='') self.fig.canvas.draw() self.ax.plot(ya,za, color='red', linestyle='--', marker='') self.fig.canvas.draw() subscribe('UPDATE_LRUGL_GRAPH', 'DRAW_INFO') subscribe('DRAW_INFO', fig_ax_request) subscribe('LRUGL_FIRST_DRAW', 'DRAW_FIRST') subscribe('DRAW_FIRST', fig_ax_request) The subscribes get lists to fill the graph. The first expression updates the graph when data already exists in a gui table. The second expression fills the graph by loading a file. So the parameters "x","y","x2" are lists.