python-3.x - 将点连接到 matplotlib 散点图中的中心
问题描述
我是 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()
推荐阅读
- google-apps-script - 具有数据验证(下拉)的单元格具有值“未定义”。为什么?
- php - 如何从使用来自不同命名空间的类的命令行执行 php 文件?
- c# - c# FTDI 24bit 二进制补码工具
- amazon-cloudfront - CloudFront 到公共或私有 Route53 托管区域
- optuna - 在 Optuna 培训中关闭警告
- google-apps-script - 获取外部 URL 并保存到云端硬盘
- c# - 如何使用 WiFi 加密狗在 WiFi MCU(ESP8266、ESP32)和 PC 之间发送、获取、交换数据?
- r - 如何使用来自另一个数据帧的多列对数据帧进行子集化
- python - 如何使用 BeautifulSoup 从表数据中删除一行中的特定类
- jenkins - 当新文件夹完全复制到目录时,我需要触发 Jenkins 作业