Matplotlib was introduced keeping in mind, only two-dimensional plotting. But at the time when the release of 1.0 occurred, the 3d utilities were developed upon the 2d and thus, we have 3d implementation of data available today! The 3d plots are enabled by importing the mplot3d toolkit. In this article, we will discuss the surface plots and contour plots in detail.
A Surface Plot is a representation of a three-dimensional dataset. It describes a functional relationship between two independent variables X and Z and a designated dependent variable Y, rather than showing the individual data points. It is a companion plot of the contour plot. It is similar to the wireframe plot, but each face of the wireframe is a filled polygon. This helps to create the topology of the surface which is being visualized.
Surface plots are used to :
- Visualise loss functions in machine learning and deep learning
- Visualise store or state value functions in reinforcement learning
Creating 3D surface Plot
The axes3d present in Matplotlib’s mpl_toolkits.mplot3d toolkit provides the necessary functions used to create 3D surface plots.Surface plots are created by using
ax.plot_surface(X, Y, Z)
where X and Y are 2D arrays of points of x and y while Z is a 2D array of heights.
Contour plots also called level plots are a tool for doing multivariate analysis and visualizing 3-D plots in 2-D space. If we consider X and Y as our variables we want to plot then the response Z will be plotted as slices on the X-Y plane due to which contours are sometimes referred to as Z-slices or iso-response.
Contour plots are widely used to visualize density, altitudes, or heights of the mountain as well as in the meteorological department. Due to such wide usage
matplotlib.pyplot provides a method contour to make it easy for us to draw contour plots.
Creating Contour plots
The matplotlib.pyplot.contour() are usually useful when Z = f(X, Y) i.e Z changes as a function of input X and Y. A contourf() is also available which allows us to draw filled contours.
matplotlib.pyplot.contour([X, Y, ] Z, [levels], **kwargs)
- X, Y: 2-D NumPy arrays with the same shape as Z or 1-D arrays such that
len(Y)==N(where M and N are rows and columns of Z)
Z: The height values over which the contour is drawn. The shape is (M, N)
levels: Determines the number and positions of the contour lines/regions.
- Exploration with Hexagonal Binning and Contour Plots
- 3D Cone Plots using Plotly in Python
- 3D Volume Plots using Plotly in Python
- 3D Line Plots using Plotly in Python
- Stem and Leaf Plots in Python
- Seaborn | Distribution Plots
- Seaborn | Categorical Plots
- Seaborn | Regression Plots
- Relational plots in Seaborn - Part I
- Relational plots in Seaborn - Part II
- Visualising ML DataSet Through Seaborn Plots and Matplotlib
- Plotting different types of plots using Factor plot in seaborn
- 3D Contour Plotting in Python using Matplotlib
- Contour Plot using Matplotlib - Python
- Matplotlib.pyplot.contour() in Python
- Matplotlib.axes.Axes.contour() in Python
- 3D Surface plotting in Python using Matplotlib
- Tri-Surface Plot in Python using Matplotlib
- Python | Percentage increase in the total surface area of the cuboid
- Python Program to find volume, surface area and space diagonal of a cuboid
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.