Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib 如何设置固定在轴上的三维散点图的标记大小?_Matplotlib_3d_Marker_Scatter - Fatal编程技术网

Matplotlib 如何设置固定在轴上的三维散点图的标记大小?

Matplotlib 如何设置固定在轴上的三维散点图的标记大小?,matplotlib,3d,marker,scatter,Matplotlib,3d,Marker,Scatter,我以前问过类似的问题(),但现在我想在3D中做。我该怎么做 谢谢在2D情况下,您需要自己绘制球体。如果你想要形状优美的球体,这意味着要画很多补丁,因此速度会很快变慢 下面是一个基本的方法: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np def plot_shere(ax, x, y, z, r, resolution=100, **kwargs): "

我以前问过类似的问题(),但现在我想在3D中做。我该怎么做


谢谢

在2D情况下,您需要自己绘制球体。如果你想要形状优美的球体,这意味着要画很多补丁,因此速度会很快变慢

下面是一个基本的方法:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

def plot_shere(ax, x, y, z, r, resolution=100, **kwargs):
    """ simple function to plot a sphere to a 3d axes """

    u = np.linspace(0, 2 * np.pi, resolution)
    v = np.linspace(0, np.pi, resolution)

    xx = r * np.outer(np.cos(u), np.sin(v)) + x
    yy = r * np.outer(np.sin(u), np.sin(v)) + y
    zz = r * np.outer(np.ones(np.size(u)), np.cos(v)) + z

    ax.plot_surface(xx, yy, zz,  rstride=4, cstride=4, **kwargs)

# create some random data (set seed to make it reproducable)
np.random.seed(0)
(x,y,z) = np.random.randint(0,10,(3,5))
r = np.random.randint(2,4,(5,))

# set up the figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# loop through the data and plot the spheres
for p in zip(x,y,z,r):
    plot_shere(ax, *p, edgecolor='none', color=np.random.rand(3))

# set the axes limits and show the plot
ax.set_ylim([-4,14])
ax.set_xlim([-4,14])
ax.set_zlim([-4,14])
plt.show()
结果: