×

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:

AX Contour Python

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:

AX Contour Python

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.


Related Topics

Import Function in Python

In Python programming language, the import keyword plays an important role in the whole code because it makes one module make available in another module. Import is used to structure...

3 minutes read.

Data Class in Python

Introduction In Python 3.7, the dataclass modules are introduced as a practical tool for creating organized classes designed specifically for data storage. These classes contain specific attributes and capabilities to deal...

6 minutes read.

List in Python

What is List in Python In Python, lists are used to store the multiple values in one variable. We can say that list is the collection of similar as well as...

3 minutes read.

How to create a DataFrames in Python

How to create a DataFrames in Python Data Frame is a data structure in which data is stored in tabular form. They can also be referred as two-dimensional collection of data. Various...

5 minutes read.

Write Dictionary to CSV in Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

4 minutes read.

Iterators in Python

Introduction In Python, an iterator is defined as an object that enables traversing through all the values of a collection. It contains the countable number of values. The iterator is utilized to...

4 minutes read.

Python String isalpha() method

Python String isalpha() method The string.isalpha () method in Python returns a boolean value true if all characters in the  string are alphabetic else for any other value it returns false. Syntax isalpha()  Parameter NA Return This...

1 minute read.

Python Program to Print Sum of all Elements in an Array

Python program to print sum of all elements in an array A set of objects stored in contiguous memory locations is referred to as an array. The concept is to keep...

2 minutes read.

Python hash() function

Python hash() function The hash() function in Python returns the hash value of the object (if it has one).  Syntax hash(object) Parameter obj : This parameter represents the object which we need to convert into hash. Return This...

1 minute read.

Count Number of Keys in Dictionary Python

Dictionary is a particular data type in python. Dictionary stores unique values by taking different keys and their assigned values. Through this article, we will learn about python dictionary count,...

3 minutes read.

Python for Loop Increment

Introduction In general, loops are employed for sequential traversal. It belongs to the definite iteration category. Definite iterations imply that the number of iterations is explicitly set in advance.  In this article,...

4 minutes read.

Confusion Matrix Visualization Python

The confusion matrix is a two-dimensional array that compares the anticipated and actual category labels. These are the True Positive, True Negative, False Positive, and False Negative classification categories for...

4 minutes read.

Hog Descriptor Opencv Python

Python programming language: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a...

3 minutes read.

Imread Python

In this walkthrough, we'll go over the specifics of using the imread() method of OpenCV-Python and various methods for loading images. Imread is an Image reading library. One of the most helpful...

7 minutes read.

Linear Regression using Sklearn with Example

This article will examine Python's global, local and non-local variables and show you how to use them to write code without problems. Let's quickly review what a variable in Python is...

8 minutes read.

How to plot multiple linear regression in Python

This article lets us look into linear regression in Python and how we can plot multiple linear regressions in it. Linear regression One of the simplest and most widely used Machine Learning...

4 minutes read.

Python String rjust() method

Python String rjust() method The string.rjust() method in Python returns a right-justified string of a given minimum width where the padding is done using the specified fillchar (default is a space). It returns...

2 minutes read.

Python getattr() function

Python getattr() function The getattr() function in Python returns the value of the named attribute for the given object. Syntax getattr(object, name[, default]) Parameter object: It is a required parameter which represents an object. name: This parameter represents the...

1 minute read.

Python SciPy Library

Introduction SciPy, a logical library for Python is an open-source, BSD-authorized library for arithmetic, science, and design. The SciPy library relies upon NumPy, which gives advantageous and quick N-dimensional exhibit control....

6 minutes read.

Struct Module in Python

What is a structure in Python? An entity that holds data in form of a structure is called a data structure. In Python, the data structure includes tuples, lists, dictionaries, and...

4 minutes read.