Python 如何使用Matplotlib在三维界面中绘制多个节点之间的线

Python 如何使用Matplotlib在三维界面中绘制多个节点之间的线,python,matplotlib,graph,3d,Python,Matplotlib,Graph,3d,我想画出如下图所示的节点,这些节点随机均匀分布在一个尺寸为10×10×10mm的三维隔间区域中如何在Python中执行此操作? 更多信息:此处,(*)节点称为目标节点,(·)节点称为源节点。使用特定的SINRmin要求评估两个节点之间的可用通信链路,并用黑色虚线(称为段)绘制。这里,SINRmin的值为8db 这是我的代码,我所做的: import numpy as np import matplotlib.pyplot as plt n = 50 x1, x2 = 0.01, 0.1 y

我想画出如下图所示的节点,这些节点随机均匀分布在一个尺寸为10×10×10mm的三维隔间区域中如何在Python中执行此操作?

更多信息:此处,(*)节点称为目标节点,(·)节点称为源节点。使用特定的SINRmin要求评估两个节点之间的可用通信链路,并用黑色虚线(称为段)绘制。这里,SINRmin的值为8db

这是我的代码,我所做的:

import numpy as np
import matplotlib.pyplot as plt

n = 50

x1, x2 = 0.01, 0.1
y1, y2 = 0.01, 0.1    
z1, z2 = 0.01, 0.1

xs = (x2 - x1)*np.random.rand(n) + x1
ys = (y2 - y1)*np.random.rand(n) + y1
zs = (z2 - z1)*np.random.rand(n) + z1

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
ax.plot(xs, ys, zs, "go")
ax.plot(xs, ys, zs, "k--")
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()
我的输出:


根据您的代码,此代码将演示如何设置标记的形状、大小和线型。在绘图中,
从节点
呈绿点形状,
到节点
呈红星形状

import numpy as np
import matplotlib.pyplot as plt

n = 50

x1, x2 = 0.01, 0.1
y1, y2 = 0.01, 0.1    
z1, z2 = 0.01, 0.1

# (origin) nodes
xs = (x2 - x1)*np.random.rand(n) + x1
ys = (y2 - y1)*np.random.rand(n) + y1
zs = (z2 - z1)*np.random.rand(n) + z1

fig = plt.figure(figsize=(9,9))
ax = fig.add_subplot(111,projection='3d')
#ax.plot(xs, ys, zs, "go")
#ax.plot(xs, ys, zs, "k--")
#ax.plot(xs, ys, zs, 'g.--', linewidth=0.8, markersize=8)
ax.plot(xs, ys, zs, 'g.', linewidth=0.8, markersize=8)

# (destination) nodes
x1,y1,z1 = 0.2, 0.2, 0.2
xs2 = (x2 - x1)*np.random.rand(n) + x1
ys2 = (y2 - y1)*np.random.rand(n) + y1
zs2 = (z2 - z1)*np.random.rand(n) + z1
#ax.plot(xs2, ys2, zs2, 'r*--', linewidth=0.8, markersize=8)
ax.plot(xs2, ys2, zs2, 'r*', linewidth=0.8, markersize=8)

#ax.plot(xs, ys, zs, color="k", marker=".")
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

# Plot line between (origin) from-nodes to (destination) to-nodes
# Assuming the lines apply in succeeding order between 2 groups of data
from_pts = []
for ea in np.stack((xs, ys, zs), axis=-1):
    from_pts.append(ea)

dest_pts = []
for ea2 in np.stack((xs2, ys2, zs2), axis=-1):
    dest_pts.append(ea2)

for from_to in zip(from_pts, dest_pts):
    #print("From:", from_to[0])
    #print("To:", from_to[1])
    ax.plot([from_to[0][0],from_to[1][0]], 
            [from_to[0][1],from_to[1][1]], 
            [from_to[0][2],from_to[1][2]], "b--", linewidth=0.6)
    pass

plt.show()
输出:


这篇文章不清楚。您的问题涉及在一定范围内绘制,您成功了,您具体要求什么?绘制方向图?看看FancyArrowPatch