
Key 3D Plots using Matplotlib: Surface Plot and Tri-surface plots After that, we are plotting the graph with the above points, and later we are showing the figure containing the 2 3D graphs.Then, we are creating a wide range of elements and storing them in the form of arrays in X1, Y1, and Z1.After that, we move to the second plot, where we define the 2nd subplot parameters.Using plot_wireframe we are plotting the points in the 3D axis. Then, using the values of X and Y, we are creating Z by forming an expression.After that, we are taking X, Y which contain a series of points, and with them, we are creating a meshgrid which is made up of two 1D dimensional arrays and is used for matrix indexing to create an nD array.Then we are creating an empty figure where two 3D plots will be plotted.In the code, we have initialized the packages matplotlib.pyplot, and NumPy from python as usual. So for that, we will be creating two subplots in a single canvas or figure.

In the above example, we will be working with 2 3D graphs.So let us move into our code implementation. In the last and the final example, we will be creating two 3D graphs in a single figure/canvas, where we will be our 3D points. Using plot_wireframe we are creating a 3D sine and cosine curve(of different colors) with the above points created by us. Using fig.gca, we are defining that the plots that we are going to make will be of 3D projection using projection=’3d’. After that, we are creating an empty figure where we will be plotting out 3D plot.Now, we are creating the sine and the cosine curves with the help of z and z1 respectively. MeshGrid makes N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, where there is a 1-Dimensional array. Using meshgrid, we are returning coordinate matrices from coordinate vectors.That’s why the second curve(cosine curve) is smoother than the first curve. The difference that it creates is, the first graph will have steep curves since the difference between the points is more, whereas, in the second set, the graph will be smoother as compared to the first one because we are taking a wide range of points more than x and y. The second set of elements also ranges from -5 to 5 with each element having a difference of 0.6 from each other.

The first set of x,y have values from -5 to 5 with each of the elements having a difference of 1 from each other.


