

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Draw axis lines or the origin for Matplotlib contour plot.
- How to plot matplotlib contour?
- Contour hatching in Matplotlib plot
- Adding extra axis ticks using Matplotlib
- Plot Matplotlib 3D plot_surface with contour plot projection
- How to get coordinates from the contour in matplotlib?
- 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?
- Setting the limits on a colorbar of a contour plot in Matplotlib
- How to mark a specific level in a contour map on Matplotlib?
- How to use matplotlib.animate to animate a contour plot in Python?
- How to find the area of an image contour Java OpenCV library?
- Plotting animated quivers in Python using Matplotlib
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?
- Adding textures to graphs using Matplotlib
Advertisements