连接 Python 中两个不同数组的点
Connect points from two different arrays in Python
我正在尝试用线连接两个数组中的点。我只想连接相同位置的点(第一个来自 stapts 和第一个来自 endpts),而不是所有点。
谁能告诉我该怎么做?非常感谢。
下面我只绘制了两个散点图。
import numpy as np
import matplotlib.pyplot as plt
# First, import data file into an array
gb_data = np.genfromtxt('gb_boundaries.txt', skip_header=10)
# Now plot the starting points of the system
staptsx = [gb_data[:, 15]]
staptsy = [gb_data[:, 16]]
endptsx = [gb_data[:, 17]]
endptsy = [gb_data[:, 18]]
plt.scatter(staptsx, staptsy)
plt.show()
plt.scatter(endptsx, endptsy)
plt.show()
我相信以下应该可行,为每对点画一条线。我不确定这是否是最有效的方法,但如果你没有太多积分,你应该没问题。
toPlot = zip(staptsx, staptsy, endptsx, endptsy)
for tuple in toPlot:
plt.plot([tuple[0], tuple[2]], [tuple[1], tuple[3]], marker='o')
plt.show()
我正在尝试用线连接两个数组中的点。我只想连接相同位置的点(第一个来自 stapts 和第一个来自 endpts),而不是所有点。
谁能告诉我该怎么做?非常感谢。 下面我只绘制了两个散点图。
import numpy as np
import matplotlib.pyplot as plt
# First, import data file into an array
gb_data = np.genfromtxt('gb_boundaries.txt', skip_header=10)
# Now plot the starting points of the system
staptsx = [gb_data[:, 15]]
staptsy = [gb_data[:, 16]]
endptsx = [gb_data[:, 17]]
endptsy = [gb_data[:, 18]]
plt.scatter(staptsx, staptsy)
plt.show()
plt.scatter(endptsx, endptsy)
plt.show()
我相信以下应该可行,为每对点画一条线。我不确定这是否是最有效的方法,但如果你没有太多积分,你应该没问题。
toPlot = zip(staptsx, staptsy, endptsx, endptsy)
for tuple in toPlot:
plt.plot([tuple[0], tuple[2]], [tuple[1], tuple[3]], marker='o')
plt.show()