Matplotlib 3D saving blank image, plt.show() not in code

180 views Asked by At

I'm writing a plotting code for a 3D plot in matplotlib and I was originally trying to scale the axes so that the x and z axes were scaled larger than the y-axis. When I tried to make these edits, however, plt.savefig() started saving a blank image. Plt.show() isn't in the code at all, which is normally what causes this error.

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')
0

There are 0 answers