D
D
Daniel2022-03-31 16:54:08
Python
Daniel, 2022-03-31 16:54:08

How to determine the value of X and Y by clicking the cursor on the plot area?

How to create an XY area for a future chart, where you can click the cursor on any valid value from X to Y, and find out the exact coordinates of the point after pressing ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2022-03-31
@anudas

First you need to select the library in which the graph will be drawn. the simplest, even children are taught on it - this is a turtle. It can make simple games and read click coordinates
https://docs.python.org/3/library/turtle.html

R
rPman, 2022-03-31
@rPman

mathematics? graph is the graph of a function?
When you draw a graph yourself, you must implement a formula that calculates screenX and screenY from x and y=F(x) of your graph, i.e. coordinates (most often in pixels) of points on the screen,
respectively, the reverse process, from a click on the screen, you need to write an inverse transformation
if X is usually simple, let minx and maxx be the minimum and maximum values ​​\u200b\u200bon the graph for x, and the graph is drawn on the screen from minScreenX to maxScreenX, then calculating the point screenx = ((x-minx)*(maxScreenX-minScreenX)/(maxx-minx))+minScreenX counts screeny
in the same way, but instead of x you take y=f(x), miny, maxy and minScreenY, maxScreenY respectively
the inverse transformation for x will not be a problem, this is a school course, but for y it’s a little more complicated, if f (x) can analytically derive the inverse function x = FF (y) then everything is simple, otherwise, there is an easy way - to store in memory in array all function values ​​for each screenX point on the screen as an associative array ff[x]=[...] and use it instead of the inverse function

L
lz961, 2022-04-01
@lz961

# x = ....
# y = ....

from  matplotlib import pyplot as plt
fig =  plt.figure()

def press_event(event):
    print (event.xdata, event.ydata)

fig.canvas.mpl_connect('button_press_event', press_event)
ax = fig.add_subplot(111)

ax.plot(x, y)
plt.show()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question