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 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.
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.
Syntax: matplotlib.pyplot.contour([X, Y, ] Z, [levels], **kwargs)
X, Y: 2-D numpy arrays with same shape as Z or 1-D arrays such that len(X)==M and len(Y)==N (where M and N are rows and columns of Z)
Z: The height values over which the contour is drawn. Shape is (M, N)
levels: Determines the number and positions of the contour lines / regions.
Below examples illustrate the
matplotlib.pyplot.contour() function in matplotlib.pyplot:
Example #1: Plotting of Contour using
contour() which only plots contour lines.
Example #2: Plotting of contour using
contourf() which plots filled contours.
- 3D Contour Plotting in Python using Matplotlib
- Matplotlib.axes.Axes.contour() in Python
- Matplotlib.pyplot.contour() in Python
- Surface plots and Contour plots in Python
- Make a violin plot in Python using Matplotlib
- Plot the magnitude spectrum in Python using Matplotlib
- Plot the phase spectrum in Python using Matplotlib
- Plot Mathematical Expressions in Python using Matplotlib
- Plot the power spectral density using Matplotlib - Python
- Box Plot in Python using Matplotlib
- Plot a pie chart in Python using Matplotlib
- Simple Plot in Python using Matplotlib
- Plot 2-D Histogram in Python using Matplotlib
- Tri-Surface Plot in Python using Matplotlib
- Plot a quadrilateral mesh in Python using Matplotlib
- Create a pseudocolor plot of an unstructured triangular grid in Python using Matplotlib
- Exploration with Hexagonal Binning and Contour Plots
- Autocorrelation plot using Matplotlib
- Matplotlib.axes.Axes.plot() in Python
- Matplotlib.pyplot.plot() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.