【问题标题】:Cube in python - setting of the color of scatterpython中的Cube - 散点颜色的设置
【发布时间】:2021-03-11 06:15:27
【问题描述】:

请问如何防止散点图根据视角改变颜色?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from itertools import product, combinations

fig = plt.figure(figsize=[10,6])
ax = fig.gca(projection='3d')
ax.azim = -112   # y rotation (default=270)
ax.elev = 31     # x rotation (default=0)

ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.2, 1, 1, 1]))

r = [-1, 1]
for s, e in combinations(np.array(list(product(r, r, r))), 2):
    if np.sum(np.abs(s-e)) == r[1]-r[0]:
        ax.plot3D(*zip(s, e), color='black', lw=1.5)

x_w = [0.5, 0.3]
y_w = [0, 0.6]
z_w = [0, -0.6]
ax.scatter(x_w, y_w, z_w, marker = 'o', s=500, facecolors=(0, 0, 0, 0), edgecolors = 'black')

ax._axis3don = False
plt.show()

【问题讨论】:

    标签: python python-3.x matplotlib 3d


    【解决方案1】:

    避免这种情况的一种解决方案是通过单独绘制每个点

    for i in range(len(x_w)):
        ax.scatter(x_w[i], y_w[i], z_w[i], marker = 'o', s=500, facecolors=(0, 0, 0, 0), edgecolors = 'black' )
    

    如果这不适合您,您可能需要查看thisthis 线程。参数depthshade = False 可能是您正在寻找的解决方案。不幸的是,我无法在关闭depthshade 的情况下运行代码。它不适用于在我的 matplotlib 安装中具有多个点的实例,但 this link 可能会为您提供解决方案。

    【讨论】:

      猜你喜欢
      • 2017-11-11
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 2013-07-14
      • 2020-12-04
      • 1970-01-01
      相关资源
      最近更新 更多