0

我正在为 matplotlib 中的 3D 绘图编写绘图代码,我最初试图缩放轴,以便 x 和 z 轴的缩放比例大于 y 轴。但是,当我尝试进行这些编辑时, plt.savefig() 开始保存空白图像。Plt.show() 根本不在代码中,这通常是导致此错误的原因。

fig = plt.figure(figsize=(10,10))
ax = fig.gca(projection='3d')
ax.set_xlim3d(5,8)
ax.set_ylim3d(8.5,10)
ax.set_zlim3d(6,9.5)

color_list = ['r', 'b', 'g', 'k','m','y','orange','lightblue','olivedrab','navy','slategrey','forestgreen','maroon','purple','indigo','crimson','cyan','darkgoldenrod','chocolate','turquoise','steelblue','rosybrown','lime','deeppink','lightgreen']

j=0

for vector in lattice_vector_list:
    if vector[0] >= x_limit[0] and vector[1] >= y_limit[0] and vector[2] <= z_limit[1]:
        ax.scatter(vector[0], vector[1], vector[2], zdir='z', c='burlywood',alpha=0.15)

for vector in min_lattice_vector_list:
    if vector[0] >= x_limit[0] and vector[1] >= y_limit[0] and vector[2] <= z_limit[1]:
        ax.scatter(vector[0], vector[1], vector[2], zdir='z', c=color_list[j])
    j+=1

x_scale = 3
y_scale = 1
z_scale = 3

scale = np.diag([x_scale, y_scale, z_scale, 1.0])
scale = scale*(1.0/scale.max())
scale[3,3] = 1.0

def short_proj():
    return np.dot(Axes3D.get_proj(ax), scale)

ax.get_proj = short_proj

ax.set_xlabel('a')
ax.set_ylabel('b')
ax.set_zlabel('c')

plt.savefig('DATNBZ_Lattice.png')
4

0 回答 0