首页 > 解决方案 > 在python中的点之间绘制网格线

问题描述

我在(x,y)飞机上有 6 个点:x=[x1,x2,x3,x4,x5,x6]y=[y1,y2,y3,y4,y5,y6]

import matplotlib.pyplot as plt    
x = [0, 2, 4, 0, 2, 4, 0, 2, 4]
y = [0, 0, 0, 3, 3, 3, 7, 7, 7]

plt.scatter(x, y)
plt.show()

我想在两点之间,在每个轴上绘制完全平行的线x,y(如photo)。以及如何在图表上隐藏 x 和 y 轴。我想绘制 3 层建筑的梁柱的 2D 视图;确实matplotlib让我达到了我的目标还是我应该去其他图书馆?

标签: python

解决方案


绝对matplotlib可以做到这一点。看看他们的Rectangle Patch

示例用法(您必须根据需要对其进行修改):

import matplotlib.pyplot as plt
import matplotlib.patches as patches

fig = plt.figure()
ax = fig.add_subplot()

rect = patches.Rectangle(
    (0.1, 0.1),
    0.5,
    0.5,
    fill=False
)
ax.add_patch(rect)
fig.show()

推荐阅读