When I used surface_plot function with matplotlib version 3.6.2 on MacOS to draw a 3D image, nothing appears even the axis. When I tried to degrade matplotlib to 3.5 and run the same code, it works.
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from scipy.stats import multivariate_normal def Gaussian_Distribution(N=2, M=1000, m=0, sigma=1): mean = np.zeros(N) + m cov = np.eye(N) * sigma data = np.random.multivariate_normal(mean, cov, M) Gaussian = multivariate_normal(mean=mean, cov=cov) return data, Gaussian M = 100 data, Gaussian = Gaussian_Distribution(N=2, M=M, sigma=0.1) X, Y = np.meshgrid(np.linspace(-1,1,M), np.linspace(-1,1,M)) d = np.dstack([X,Y]) Z = Gaussian.pdf(d).reshape(M,M) fig = plt.figure(figsize=(6,4)) ax = Axes3D(fig) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='seismic', alpha=0.8) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.savefig('123.png') plt.show()
No response
3.6.2
None
That is not a recommended way to add a 3D axes to a figure since version 1.0. https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#sphx-glr-tutorials-toolkits-mplot3d-py
Change ax = Axes3D(fig) to ax = fig.add_subplot(projection='3d')
Since #24715 is documenting that Axes should not be instantiate directly, I guess that closes this.
Activity
greglucas commented on Dec 14, 2022
That is not a recommended way to add a 3D axes to a figure since version 1.0.
https://matplotlib.org/stable/tutorials/toolkits/mplot3d.html#sphx-glr-tutorials-toolkits-mplot3d-py
Change ax = Axes3D(fig) to ax = fig.add_subplot(projection='3d')
rcomer commented on Dec 14, 2022
Since #24715 is documenting that Axes should not be instantiate directly, I guess that closes this.