将点连接到 matplotlib 散点图中的中心
Connect points to center in matplotlib scatter plot
我在3维坐标系中散点;你怎么可能通过线段(或向量)将这些点中的每一个连接到框架的中心(0,0,0)?
这是使用的代码:
from numpy import random
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
N = 10
coords = random.normal(loc = 0, scale = 1, size = (N, 3))
x = coords[:, 0]
y = coords[:, 1]
z = coords[:, 2]
fig = plt.figure(figsize=(12,12))
ax = plt.axes(projection ="3d")
ax.scatter3D(x, y, z, color = "green", s = 300)
这是获得的情节:
我想得到的是:
一种选择是遍历每个点,然后使用 plot3D
从 (0, 0, 0) 到该点画一条线。
from numpy import random
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
N = 10
coords = random.normal(loc = 0, scale = 1, size = (N, 3))
x = coords[:, 0]
y = coords[:, 1]
z = coords[:, 2]
fig = plt.figure(figsize=(12,12))
ax = plt.axes(projection ="3d")
for xx, yy, zz in zip(x, y, z):
ax.plot3D([0, xx], [0, yy], [0, zz], color = "blue")
ax.scatter3D(x, y, z, color = "green", s = 300)
plt.show()
我在3维坐标系中散点;你怎么可能通过线段(或向量)将这些点中的每一个连接到框架的中心(0,0,0)? 这是使用的代码:
from numpy import random
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
N = 10
coords = random.normal(loc = 0, scale = 1, size = (N, 3))
x = coords[:, 0]
y = coords[:, 1]
z = coords[:, 2]
fig = plt.figure(figsize=(12,12))
ax = plt.axes(projection ="3d")
ax.scatter3D(x, y, z, color = "green", s = 300)
这是获得的情节:
我想得到的是:
一种选择是遍历每个点,然后使用 plot3D
从 (0, 0, 0) 到该点画一条线。
from numpy import random
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
N = 10
coords = random.normal(loc = 0, scale = 1, size = (N, 3))
x = coords[:, 0]
y = coords[:, 1]
z = coords[:, 2]
fig = plt.figure(figsize=(12,12))
ax = plt.axes(projection ="3d")
for xx, yy, zz in zip(x, y, z):
ax.plot3D([0, xx], [0, yy], [0, zz], color = "blue")
ax.scatter3D(x, y, z, color = "green", s = 300)
plt.show()