AX Contour in Python
Python Programming Language
Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It is said to be a user-friendly programing language, as the syntax for it is very simple to write and easy to understand for a beginner programmer. Python programming language is rich in libraries that can be imported easily and used to perform many different operations. In the year 1989, Guido van Rossum is the one who introduced python programming language.
It is also used in web applications; web applications like the Django and Flask frameworks are created using python. Compared to any programming language, the syntax in python is much easier. Many colleges and institutions have introduced python in their syllabus so that the students need to learn python. The biggest advantage of the python programming language is that it has a good collection of libraries widely used in machine learning, web frameworks, test frameworks, multimedia, image processing, and many more application. Python supports multiple programming paradigms, including object-oriented, imperative, functional, and procedural
AX Contour Python
A Python package called Matplotlib is a numerical and mathematical addition to the NumPy library. Axis, Tick, Line2D, Text, Polygon, and other figure elements are mostly found in the Axes Class, which also establishes the coordinate system. Additionally, Axes objects enable callbacks via a callbacks attribute. Matplotlib enables the creation of contour plots. A contour plot in mechanical engineering could display the stress gradient across a part's surface.For example, in geography and meteorology, contour lines are utilized.
matplotlib.axes.Axes.contour ( ) function:
To plot contours, use the axes.contour() function in the axes module of the matplotlib package. Sketch contour lines.A curve along which a function with two variables has a constant value is called an isoline or contour line.It is a cross-section of the function f(x, y) parallel to the x, y plane's three-dimensional graph.
Syntax:
Axes.contour(self, *args, data=None, **kwargs)
contour([X, Y, ] Z, [levels], **kwargs)
Parameters:
The following parameters are accepted by this technique and are detailed below:
- The coordinates of the values in Z are given by the parameters X and Y.
- Z: The height values across which the contour is drawn are represented by this parameter.
- Levels: The number and location of the contour lines / regions are determined by this parameter.
Returns: This gives the results below:
- C: This gives the QuadContourSet as a result.
The matplotlib.axes are shown in the examples below. The matplotlib.axesaxes.contour() function:
Example:
#importing the required functions to perform the operation
importnumpy as np
importmatplotlib.pyplot as plt
importmatplotlib.ticker as ticker
importmatplotlib
delta = 0.15
x = np.arange(-0.5, 2.5, delta)
y = np.arange(-1.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z = (np.exp(-X**2 - Y**2) - np.exp(-(X - 1)**2 - (Y - 1)**2))
fig1, ax1 = plt.subplots()
CS1 = ax1.contour(X, Y, Z)
fmt = {}
strs = ['1', '2', '3', '4', '5', '6', ]
for l, s in zip(CS1.levels, strs):
fmt[l] = s
ax1.clabel(CS1, CS1.levels, inline = True,
fmt = fmt, fontsize = 10)
ax1.set_title('matplotlib.axes.Axes.contour() Example')
plt.show()
Output:

Example 2:
#importing the required functions to perform the operation
importnumpy as np
importmatplotlib
importnumpy as np
import matplotlib.cm as cm
importmatplotlib.pyplot as plt
delta = 0.25
x = np.arange(-5.0, 5.0, delta)
y = np.arange(-3.3, 5.5, delta)
X, Y = np.meshgrid(x, y)
Z = (np.exp(-X**2 - Y**2) - np.exp(-(X - 1)**2 - (Y - 1)**2)) * 3
fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation ='bilinear', origin ='lower',
cmap ="Greens", extent =(-3, 3, -2, 2))
levels = np.arange(-1.2, 1.6, 0.2)
CS = ax.contour(Z, levels, origin ='lower', cmap ='Blues',
linewidths = 2, extent =(-3, 3, -2, 2))
zc = CS.collections[6]
plt.setp(zc, linewidth = 4)
ax.clabel(CS, levels, inline = 1, fmt ='% 1.1f',
fontsize = 14)
ax.set_title('matplotlib.axes.Axes.contour() Example')
plt.show()
Output:

Conclusion
A Python package called Matplotlib is a numerical and mathematical addition to the NumPy library. Axis, Tick, Line2D, Text, Polygon, and other figure elements are mostly found in the Axes Class, which also establishes the coordinate system. Additionally, Axes objects enable callbacks via a callbacks attribute. Matplotlib enables the creation of contour plots. A contour plot in mechanical engineering could display the stress gradient across a part's surface.