What is gca and working of plot_surface()?

In the video for 3D surface plot
axes=fig.gca(projection=‘3d’) , what is gca ?
and in the documentation of gca I cannot find any parameter which is named as projection.
Finally , how does plot_surface works and why does z parameter have to be 2d list ?

Hi @anshushahi98,

gca stands for (get current axes) - it a function used to get the reference of current axes.

there is projection argument to Axes and (gca returns object of axes) So, we provide projection argument to gca function which will further call superclass Axes and passes this argument. 3d is one type of projections available in matplotlib.

plot_surface function as the name says Create a surface plot. basically, for plotting the values like a and b we use this function.
Z parameter is the elevation of a point. Since the points are in 2D eg (-3,2) we need an elevation function that can handle or elevate 2-Dim data.
In our example elevation is calculated 3**2 + 2**2 => 13 which gives z-axis value of 13.
so for every point, the elevation is calculated and that’s the Z value.

I hope both the questions are now clear :slight_smile:

I cannot find the argument projection in the docs
26%20PM
In plot_surface if i pass x and y as 1dim list then also it says that we require a 2dim z list , that is why i asked how does plot_surface works.

Hi @anshushahi98,
First thing You won’t find projection parameter in gcd() as I told you it returns as axes an Object of Axes class, so look what happens inside the Axes…
If we go to docs you will see that Axes objects receives a parameter projection, so actually it is the Axes who is receiving projection param.
gcd func take all the params as kwargs dictionary, and sends to it’s super class i.e Axes.

Then second question of plot_surface…
as the name says plot surface* and what is a surface - a 2D area is called a surface, so why are you passing 1D list to it for plotting,

if you want to visualize anything list if 1D , use normal plot() for this purpose.

Because we had 2 dimn values therefore created a surface and third dimension (z) is always used for their elevation, so it becomes 3D plot.

Now don’t try to put 3 dimensional data as well, it won’t plot :laughing:

So to conclude,
if you want to plot anything in :
2 Dimensions - use plot()
3 Dimensions - use plot_surface()

beyond that you can’t plot

1 Like

thanks for the explanation :slight_smile: