One method to retrieve the values of the coordinates that have been clicked on a multiplot matplotlib graph is to use the mpl_connect
function to connect a function to the button_press_event
.
Here is an example code snippet:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
# define the function to handle mouse clicks
def onclick(event):
if event.inaxes:
x, y = event.xdata, event.ydata
print("Clicked at x = {:.2f}, y = {:.2f}".format(x, y))
# connect the function to the button_press_event
for ax in axs.flatten():
ax.plot([1, 2, 3], [4, 5, 6])
cid = ax.figure.canvas.mpl_connect('button_press_event', onclick)
plt.show()
In this example, the onclick
function prints the x and y coordinates of the clicked point. The mpl_connect
function is called for each subplot to connect the function to the button press event for each subplot.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-09 13:11:15 +0000
Seen: 11 times
Last updated: May 09 '23
What is the method to eliminate NA from facet_wrap in ggplot2?
What is the method for putting each value of an array into a separate cell in Excel?
What is the method for altering the color of the input text in a TextFormField in Flutter?
What is the procedure for utilizing the node-rdpjs library?
What is the method to change a PDF file to an Excel file using C#?
What is the method to make a TextButton inactive when the text field has no text?
What is the method to alter the background image in HTML?
What is the method for saving an entity with @EmbeddedId as its primary key in Hibernate?
What is the method to superimpose two seaborn density plots?