使用python无法看到矩阵图形的结果

时间:2019-08-06 05:24:52

标签: python numpy matplotlib

您能帮我解决此代码吗? 我正在使用木星,看不到结果。也许xLim或yLim有问题。

下面是整个代码,我想看一下图。



points = [[0.3036, 0.1960], [0.6168, 0.2977], [0.7128, 0.4169], [0.7120, 0.1960],[0.9377,0.2620],\
          [0.7120,0.5680],[0.3989,0.6697],[0.3028,0.7889],[0.3036,0.5680],[0.5293,0.5020]]

    theta = np.pi
    a = 0.7120
    b = 0.4320
    shiftrotateMatrix = np.array([[np.cos(theta),-np.sin(theta),-a*np.cos(theta)+b*np.sin(theta)+a],\
                                  [np.cos(theta),-np.sin(theta),-a*np.sin(theta)-b*np.cos(theta)+b],\
                                  [0,0,1]])
    points3d = points
    for x in points3d:
        x.append(1)
    pointsab = []
    for x in points3d:
        pointsab.append(np.dot(shiftrotateMatrix,x))
    finalpoints = [np.array([x[0],x[1]]) for x in pointsab]
        fig = plt.figure()
        finalbird = matplotlib.patches.Polygon(finalpoints, facecolor='yellow')
        fig, ax = plt.subplots()
        ax.set_aspect("auto")
        ax.add_patch(finalbird)

        ax.set_xlim(-2,2)
        ax.set_ylim(-2,2)
        plt.show()

enter image description here

1 个答案:

答案 0 :(得分:0)

在代码末尾执行此操作。

for point in finalpoints:
    print(point[0] - point[1])

每个单点(x,y)具有属性x-y = 0.56。您的多边形正在“显示”,但这是一条直线。