如何在Python中保持情节数字

问题描述 投票:0回答:1

我有这样的代码,其中c_X,c_Y,c_Z,X,Y,Z X_2,Y_2,Z_2,X_4,Y_4,Z_4,是点的列表(我的数据)。

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

for i in range (2):

    fig = plt.figure(i)
    ax = fig.add_subplot(111, projection='3d')

    ax.scatter(c_X,c_Y,c_Z, color = 'midnightblue')
    ax.scatter(X, Y, Z, color = 'mediumaquamarine')
    ax.scatter(X_2,Y_2,Z_2, color = 'cadetblue')
    ax.scatter(X_4,Y_4,Z_4, color = 'cadetblue')
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.set_zlabel('z')
    plt.draw()

我怎样才能在三个不同的数字中,最终得到这三个图?

python matplotlib plot figure
1个回答
1
投票

按照问题注释中的建议修改你的代码。

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

for i in range (2):

    fig = plt.figure(i)
    ax = fig.add_subplot(111, projection='3d')

    ax.scatter(c_X,c_Y,c_Z, color = 'midnightblue')
    ax.scatter(X, Y, Z, color = 'mediumaquamarine')
    ax.scatter(X_2,Y_2,Z_2, color = 'cadetblue')
    ax.scatter(X_4,Y_4,Z_4, color = 'cadetblue')
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.set_zlabel('z')
plt.show()

我认为这就是你想要的。


0
投票

如果你只有4个数字,你可以直接使用。

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(c_X,c_Y,c_Z, color = 'midnightblue')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(X, Y, Z, color = 'mediumaquamarine')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(X_2,Y_2,Z_2, color = 'cadetblue')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(X_4,Y_4,Z_4, color = 'cadetblue')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

这样行吗?

或者你可以将你的数组合并成一个X数组,一个Y数组和一个Z数组。为颜色创建一个列表并使用循环。

c = ['color1', 'color2', etc]

for i in range(k):
    plt.figure()
    ax = Axes3D(fig)
    ax.scatter(X[i], Y[i], Z[i], color=c[i])
    plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.