In this article we will learn how to plot complex number in Python using Matplotlib. Let’s discuss some concepts :
- Matplotlib : Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002.
- Complex number : A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers, and i represents the imaginary unit, satisfying the equation i2 = −1. Because no real number satisfies this equation, i is called an imaginary number.
- Complex number in Python : An complex number is represented by “ x + yi “. Python converts the real numbers x and y into complex using the function complex(x,y). The real part can be accessed using the function real() and imaginary part can be represented by imag().
- Import libraries.
- Create data of complex numbers
- Extract real and imaginary parts from complex numbers data
- Plot the extracted data.
To plot complex numbers, we have to extract its real and imaginary part and to extract and create data, we will use some methods that are explained in below examples :
Example 1 : (Simple plot with complex numbers over real and imaginary data)
Example 2 : (Using numpy for extracting real and imaginary parts)
Example 3 : (Using numpy for creating data of complex numbers and extracting real and imaginary parts)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.