- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot matplotlib contour?
To plot matplotlib contour, we can take the following steps −
Create data points for x, y and h using numpy.
Using the countourf() method, create a colored 3D (alike) plot.
Using the set_over() method, set the color for high out-of-range values when "norm.clip = False".
Using the set_under() method, set the color for low out-of-range values when "norm.clip = False".
Using the changed() method, call this whenever the mappable is changed to notify all the callbackSM listeners to the "changed" signal.
Use the show() method to display the figure.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(1, 10) y = x.reshape(-1, 1) h = x * y cs = plt.contourf(h, levels=[10, 30, 50], colors=['yellow', 'green', 'purple'], extend='both', alpha=.90) cs.cmap.set_over('red') cs.cmap.set_under('blue') cs.changed() plt.show()
Output
- Related Articles
- Contour hatching in Matplotlib plot
- Plot Matplotlib 3D plot_surface with contour plot projection
- How can Matplotlib be used to create 3 dimensional contour plot using Python?
- How do you create a legend for a contour plot in Matplotlib?
- Draw axis lines or the origin for Matplotlib contour plot.
- Setting the limits on a colorbar of a contour plot in Matplotlib
- Adding extra contour lines using Matplotlib 2D contour plotting
- How to get coordinates from the contour in matplotlib?
- How to use matplotlib.animate to animate a contour plot in Python?
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?
- How to mark a specific level in a contour map on Matplotlib?
- How to a plot stem plot in Matplotlib Python?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to plot categorical variables in Matplotlib?
- How to plot collections.Counter histogram using Matplotlib?

Advertisements