- 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
Adding extra contour lines using Matplotlib 2D contour plotting
To add extra contour lines using Matplotlib 2D contour plotting, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create e a function f(x, y) to get the z data points from x and y.
Create x and y data points using numpy.
Make a list of levels using Numpy.
Make a contour plot using contour() method.
Label the contour plot and set the title of the plot.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def f(x, y): return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x) x = np.linspace(0, 5, 50) y = np.linspace(0, 5, 40) X, Y = np.meshgrid(x, y) Z = f(X, Y) levels = np.arange(-1.0, 1.5, 0.25) CS = plt.contour(X, Y, Z, levels=levels) plt.clabel(CS, inline=1, fontsize=10) plt.title('levels = {}'.format(levels.tolist())) plt.show()
Output
- Related Articles
- Contour Plot using Python Matplotlib
- Draw axis lines or the origin for Matplotlib contour plot.
- Contour hatching in Matplotlib plot
- How to plot matplotlib contour?
- Adding extra axis ticks using Matplotlib
- Plot Matplotlib 3D plot_surface with contour plot projection
- Contour Plots using Plotly in Python
- How to get coordinates from the contour in matplotlib?
- How can Matplotlib be used to create 3 dimensional contour plot using Python?
- How to mark a specific level in a contour map on Matplotlib?
- Setting the limits on a colorbar of a contour plot in Matplotlib
- How do you create a legend for a contour plot in Matplotlib?
- How To Contour and Highlight Your Face
- How to approximate a contour shape in an image using OpenCV Python?
- How to compute the area and perimeter of an image contour using OpenCV Python?

Advertisements