繁体   English   中英

我如何在 plot 中使用 matlotlib 在 3d plot 中从同一原点开始多条线?

[英]How do i plot multiple lines from a same point of origin in a 3d plot using matlotlib in python?

更新:我犯了一个错误,使用单行坐标尝试和 plot 多行。 所以代码实际上工作得很好。 数据就是问题。 感谢所有花时间检查问题的人。

有人可以告诉我如何在 3d Z32FAC25C11A99CE497915BFC80308FFCZ Z32FA46E1B78A94D20 中使用 python 中的 x,y 坐标从原点开始 plot 多条直线。 这是我所做的,我正在尝试 plot 的坐标。 代码似乎只绘制了一行,
我希望 plot 使用循环的许多行。

"""

from matplotlib import pyplot as plt
import numpy as np
shapes = [
            {'shape_attribute': 
                {'name': 'line', 'x_points': [0, 8.68279650477334], 'y_points': [0, 5.400983523311377], 'z_points': [3, 3]}
            }, 
            {'shape_attribute': 
                {'name': 'line', 'x_points': [0, 8.68279650477334], 'y_points': [0, 5.400983523311377], 'z_points': [3, 3]}
            }, 
            {'shape_attribute': 
                {'name': 'line', 'x_points': [0, 8.68279650477334], 'y_points': [0, 5.400983523311377], 'z_points': [3, 3]}
            }, 
            {'shape_attribute': 
                {'name': 'line', 'x_points': [0, 8.68279650477334], 'y_points': [0, 5.400983523311377], 'z_points': [3, 3]}
            }, 
        ]

plt.figure()
ax = plt.axes(projection = '3d')
ax.set_ylim([0, 20]) #Sets the y axis Range
ax.set_xlim([0,14]) #Sets the x axis Range
ax.set_zlim([0, 6]) #Sets the z axis Range

for shape in shapes:
    x_cor = shape['shape_attribute']['x_points']
    y_cor = shape['shape_attribute']['y_points']
    z_cor = shape['shape_attribute']['z_points']

    ax.plot3D(x_cor, y_cor, z_cor, lw=2)

ax.set_xlabel('x') #For labeling our axes
ax.set_ylabel('y')
ax.set_zlabel('z')

plt.show() 

代码实际上工作得很好,我意识到我在为这段代码准备数据时犯了一个错误,因为坐标都是一行的。 更改坐标数据以反映多行,表明代码有效。 这是坐标的正确数据。

    shapes = [
                {'shape_attribute': 
                    {'name': 'line', 'x_points': [0, 9.099814178098228], 'y_points': [0, 4.246548332911672], 'z_points': [3, 3]}
                }, 
                {'shape_attribute': 
                    {'name': 'line', 'x_points': [0, 8.984486193062779], 'y_points': [0, 4.6524460480286765], 'z_points': [3, 3]}
                }, 
                {'shape_attribute': 
                    {'name': 'line', 'x_points': [0, 8.845171322917412], 'y_points': [0, 5.0376912384632115], 'z_points': [3, 3]}
                }, 
                {'shape_attribute': 
                    {'name': 'line', 'x_points': [0, 8.68279650477334], 'y_points': [0, 5.400983523311377], 'z_points': [3, 3]}
                }, 
            ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM