如何将x,y坐标从一个小比例的图转换为一个大得多的新matplotlib图



我使用tkinter在画布上手动绘制线条,然后记录x,y坐标。我想将这些x,y坐标转换为一个缩放非常不同的画布,并使用matplotlib绘制它们。我的tkinter画布目前的尺寸是690(x(x490(y(。我想把这些坐标转换成一个尺寸为x(从-5300到5300(和y(从-3650到3650(的图,其中0是图的中心。如何进行范围/比例转换?谢谢

当前tkinter画布坐标范围:

root = tk.Tk()
background_image=tk.PhotoImage(file="Pitch2.png")
root.resizable(width=True, height=True)
root.wm_attributes("-topmost", 1)
canvas = tk.Canvas(root, bg="white", width=690, height=560)

所需matplotlib范围:

fig,ax = plt.subplots()
plt.ylim(-3650, 3650)
plt.xlim(-5300, 5300)
filename = os.path.join(os.getcwd(),'Pitch.png')
im = plt.imread(filename)
graph_2, = ax.plot([], marker='.')

matplotlib图中有7300个像素,即[-36503650]。您的Tk图像中有690个。

因此,将你的Tkx坐标乘以7300/690,并将结果加至-3650,得到matplotlibx坐标:

mpltx = (Tkx * 7300/690) - 3650 
mplty = (Tky * 10600/560) - 5300

请记住,在Numpy中,y坐标出现在x坐标之前。

最新更新