![]() In this case, it checks if the click is within 1% of the x-axis range of the plot, but you can adjust this to make it more or less sensitive depending on your needs. You can adjust the 0.01 factor to change the sensitivity of the picking event. Finally, it checks if the distance is less than 1% of the x-axis range of the plot, and prints "Line picked." if it is. Then, it calculates the distance between the x-coordinate of the click event and the x-coordinate of the line using the get_xdata method. This code first checks if the click event is within the axes of the plot. If distance < self.ax.get_xbound() * 0.01: ![]() Here's the updated on_click method that should work correctly:ĭistance = abs(event.xdata - _xdata()) To fix this, you can calculate the distance between the click event and the line using the dist method of the Line2D object. The issue with your code is that the contains method of the Line2D object returned by axvline is always returning True, regardless of where you click, because you're not checking if the click is within a certain distance of the line. But it prints "Line picked" wherever I click. The function "on_click" is a callback function to mouse clicking events that (should) print "Line picked." whenever I click near the line. Main()The constructor creates the plot, the line, and connects to mouse events via the function "connect". On the other hand, a Scatter Plot enables you to visualize critical data variables. We can connect scatter plot points with a line by calling show () after we have called both scatter () and plot (), calling plot () with the line and point attributes, and using the keyword zorder to assign the drawing order. ![]() Self.line = self.ax.axvline( x = 0.5, **kwargs )Ĭid = _connect( 'button_press_event', self.on_click ) A Line Chart helps you display patterns and trends of variables in your data. However, wherever I click, the line is picked, and I do not understand why. I am trying to pick a vertical line that I draw on a X-Y plot when I click near the line. ![]() I have an issue with a picking event using the matplotlib library. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |