python - Matplotlib 中绘制的点之间的连接线

标签 python matplotlib

我有 4 个 X 和 Y 列表,我用 matplotlib.pyplot 分别绘制,即 point1[x1,y1]、point2[x2,y2]、point3[x3,y3] 和 point4[x4,y4]。我在图中试图做的是将 point1 连接到 point2,point2 连接到 point3,等等,直到所有 4 个点都连接起来,在我的例子中这将代表一个正方形。这些数据是我正在研究的矩形泵的动态 x 和 y 位移,该数据显示了船舶月池内是否超出了位移限制。

这是我到目前为止的代码,它给出了以下图和生成的图:

Generated plot

## SSLP displacement time histories to be plotted
point1 = (3.61, 4, -3)
point2 = (3.61, -4, -3)
point3 = (-3.61, -4, -3)
point4 = (-3.61, 4, -3)
SSLPXPoint1 = SSLP.TimeHistory('X', 1, objectExtra=OrcFxAPI.oeBuoy(point1))
SSLPYPoint1 = SSLP.TimeHistory('Y', 1, objectExtra=OrcFxAPI.oeBuoy(point1))
SSLPXPoint2 = SSLP.TimeHistory('X', 1, objectExtra=OrcFxAPI.oeBuoy(point2))
SSLPYPoint2 = SSLP.TimeHistory('Y', 1, objectExtra=OrcFxAPI.oeBuoy(point2))
SSLPXPoint3 = SSLP.TimeHistory('X', 1, objectExtra=OrcFxAPI.oeBuoy(point3))
SSLPYPoint3 = SSLP.TimeHistory('Y', 1, objectExtra=OrcFxAPI.oeBuoy(point3))
SSLPXPoint4 = SSLP.TimeHistory('X', 1, objectExtra=OrcFxAPI.oeBuoy(point4))
SSLPYPoint4 = SSLP.TimeHistory('Y', 1, objectExtra=OrcFxAPI.oeBuoy(point4))

# setup plot
caseName = os.path.splitext(info.modelFileName)[0]
point1Plot = [3.61, 4]
point2Plot = [3.61, -4]
point3Plot = [-3.61, -4]
point4Plot = [-3.61, 4]
vesselPointsX = [90.89, 100.89, 100.89, 90.89, 90.89]
vesselPointsY = [5, 5, -5, -5, 5]
moonpoolCLX = [89, 103]
moonpoolCLY = [0, 0]
fig = plt.figure(figsize=(20, 15))
ax = fig.add_subplot(1, 1, 1)
plt.plot(vesselPointsX, vesselPointsY, 'r', lw=2, label='OCV Moonpool Limits')
plt.plot(moonpoolCLX, moonpoolCLY, 'k--', label='Moonpool CL')
plt.plot(SSLPXPoint1, SSLPYPoint1, 'k')
plt.plot(SSLPXPoint2, SSLPYPoint2, 'k')
plt.plot(SSLPXPoint3, SSLPYPoint3, 'k')
plt.plot(SSLPXPoint4, SSLPYPoint4, 'k')
ax.set_title("SSLP Maximum Offsets Inside Moonpool for {}".format(caseName), fontsize=20)
ax.set_xlabel('Distance Along OCV from Stern [m]', fontsize=15)
ax.set_ylabel('Distance from Moonpool Centerline, (+) Towards Portside [m]', fontsize=15)
ax.set_xlim(89, 103)
ax.set_ylim(-7, 7)
plt.gca().set_aspect('equal', adjustable='box')
plt.draw()
plt.legend()
plt.tight_layout()
plt.show()

任何帮助将不胜感激。

谢谢

布莱恩

最佳答案

这应该对你有帮助。进行更改。

from matplotlib.pyplot import plot, show
plot([SSLPXPoint1, SSLPXPoint2], [SSLPYPoint1, SSLPYPoint2])
plot([SSLPXPoint3, SSLPXPoint2], [SSLPYPoint3, SSLPYPoint2])
plot([SSLPXPoint3, SSLPXPoint4], [SSLPYPoint3, SSLPYPoint4])
show()

已编辑,因为上一个连接了所有点。

关于python - Matplotlib 中绘制的点之间的连接线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34911902/

相关文章:

javascript - python selenium 将键发送到只读文本框

python - Visual Studio Code Python 笔记本输出扩展?

python - 将发散颜色居中至零

Python Seaborn Distplot Y 值对应给定的 X 值

python - 使用 Beautiful Soup 从损坏的 <a> 标签中检索内容

python - 错误 : nothing to repeat at position 0 using regex in python

python - 如何在嵌套饼图中重新排列和设置颜色

image - matplotlib imshow():如何制作动画?

python - PostgreSQL 日期时间类型的最佳数据类型

python - 将 matplotlib png 转换为 base64 以便在 html 模板中查看