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

Python 如何将x、y坐标从一个小比例的图形转换为一个大得多的新matplotlib图形?,python,matplotlib,tkinter,Python,Matplotlib,Tkinter,我使用tkinter在画布上手动绘制线条,然后记录x,y坐标。我想将这些x,y坐标转换成一个不同比例的画布,并使用matplotlib绘制它们。我的tkinter帆布目前的尺寸为690(x)x 490(y)。我想把这些坐标转换成一个尺寸为x(从-5300到5300)和y(从-3650到3650)的图,其中0是图的中心。如何进行范围/比例转换?谢谢 当前tkinter画布坐标范围: root = tk.Tk() background_image=tk.PhotoImage(file="P

我使用tkinter在画布上手动绘制线条,然后记录x,y坐标。我想将这些x,y坐标转换成一个不同比例的画布,并使用matplotlib绘制它们。我的tkinter帆布目前的尺寸为690(x)x 490(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
plot中有7300个像素,即[-36503650]。在您的
Tk
图像中有690个字符

因此,将您的
Tk
x坐标乘以
7300/690
,并将结果添加到-3650,以获得
matplotlib
x坐标:

mpltx = (Tkx * 7300/690) - 3650 

mplty = (Tky * 10600/560) - 5300
请记住,在Numpy中,y坐标位于x坐标之前