首页 > 解决方案 > 如何在 Python 中保存绘图图形

问题描述

我有这段代码,其中 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()

最后,我怎样才能持有或获得 3 个不同数字的 3 个地块?

标签: pythonmatplotlibplotfigure

解决方案


按照问题评论中的建议修改您的代码。

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()

我认为这可以满足您的要求。


推荐阅读