First, define your complex function as a function of (Re(x), Im(x)). In complex analysis, you can decompose any complex function into its real parts and imaginary parts. In other words:

F(x) = Re(x) + i*Im(x) 

In the case of a two-dimensional grid, you can obviously extend to defining the function in terms of (x,y). In other words:

F(x,y) = Re(x,y) + i*Im(x,y) 

In your case, I'm assuming you'd want the 2D approach. As such, let's use I and J to represent the real parts and imaginary parts separately. Also, let's start off with a simple example, like cos(x) + i*sin(y) which is based on the very popular Euler exponential function. It isn't exact, but I modified it slightly as the plot looks nice.

Here are the steps you would do in MATLAB:

  1. Define your function in terms of I and J
  2. Make a set of points in both domains - something like meshgrid will work
  3. Use a 3D visualization plot - You can plot the individual points, or plot it on a surface (like surf, or mesh).

NB: Because this is a complex valued function, let's plot the magnitude of the output. You were pretty ambiguous with your details, so let's assume we are plotting the magnitude.

Let's do this in code line by line:

% // Step #1
F = @(I,J) cos(I) + i*sin(J);

% // Step #2
[I,J] = meshgrid(-4:0.01:4, -4:0.01:4);

% // Step #3
K = F(I,J);

% // Let's make it look nice!
mesh(I,J,abs(K));
xlabel('Real');
ylabel('Imaginary');
zlabel('Magnitude');
colorbar;

This is the resultant plot that you get:

Let's step through this code slowly. Step #1 is an anonymous function that is defined in terms of I and J. Step #2 defines I and J as matrices where each location in I and J gives you the real and imaginary co-ordinates at their matching spatial locations to be evaluated in the complex function. I have defined both of the domains to be between [-4,4]. The first parameter spans the real axis while the second parameter spans the imaginary axis. Obviously change the limits as you see fit. Make sure the step size is small enough so that the plot is smooth. Step #3 will take each complex value and evaluate what the resultant is. After, you create a 3D mesh plot that will plot the real and imaginary axis in the first two dimensions and the magnitude of the complex number in the third dimension. abs() takes the absolute value in MATLAB. If the contents within the matrix are real, then it simply returns the positive of the number. If the contents within the matrix are complex, then it returns the magnitude / length of the complex value.

I have labeled the axes as well as placed a colorbar on the side to visualize the heights of the surface plot as colours. It also gives you an idea of how high and how long the values are in a more pleasing and visual way.

As a gentle push in your direction, let's take a slice out of this complex function. Let's make the real component equal to 0, while the imaginary components span between [-4,4]. Instead of using mesh or surf, you can use plot3 to plot your points. As such, try something like this:

F = @(I,J) cos(I) + i*sin(J);

J = -4:0.01:4;
I = zeros(1,length(J));

K = F(I,J);
plot3(I, J, abs(K));
xlabel('Real');
ylabel('Imaginary');
zlabel('Magnitude');
grid;

plot3 does not provide a grid by default, which is why the grid command is there. This is what I get:

As expected, if the function is purely imaginary, there should only be a sinusoidal contribution (i*sin(y)).

You can play around with this and add more traces if you need to.

Hope this helps!

Answer from rayryeng on Stack Overflow
🌐
MathWorks
mathworks.com › matlabcentral › fileexchange › 77560-imaginary-and-real-number-3d-plot
Imaginary and real number 3D Plot - File Exchange - MATLAB Central
July 1, 2020 - How to extract Real and Imaginary from complex numbers then plot it. You can imagine the theory of the complex numbers corresponding to sine wave. Hayder Amily (2025). Imaginary and real number 3D Plot (https://www.mathworks.com/matlabcentral/fileexchange/77560-imaginary-and-real-number-3d-plot), ...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 354370-how-to-plot-real-and-complex-parts-of-a-function-in-3d
How to plot real and complex parts of a function in 3d? - MATLAB Answers - MATLAB Central
August 29, 2017 - I have found a way, I think to graph the 3d plot by using resources in previously asked questions. My code looks as such: ... My question is how do I split this graph into 2 subplots where I am showing the real and the complex independently? I don't see that type of question either in the Help section or in previously posted questions... Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral/answers/354370-how-to-plot-real-and-complex-parts-of-a-function-in-3d#answer_842094
🌐
MathWorks
mathworks.com › matlab › graphics › 2-d and 3-d plots › line plots
Plot Complex Numbers - MATLAB & Simulink
In this representation, you can plot a complex number as a point in the polar coordinates with radius ... θ (the counterclockwise angle between the positive real axis and the line connecting the point to the origin). Create a vector that contains the complex numbers 3 + 4i, -4 - 3i, 1 - 2i, and -1 - 1i.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 125194-need-help-with-3d-surface-plot-of-complex-function
Need help with 3D surface plot of complex function - MATLAB Answers - MATLAB Central
April 10, 2014 - https://www.mathworks.com/matlabcentral/answers/125194-need-help-with-3d-surface-plot-of-complex-function#answer_132884 ... s is a complex number and so it's F(s) (z in your code).
🌐
MathWorks
mathworks.com › matlabcentral › answers › 33474-convert-complex-matrix-to-3d-plot
convert complex matrix to 3D plot - MATLAB Answers - MATLAB Central
March 26, 2012 - i have a complex matrix (480*640double) ,i cant plot it to 3D coz i had ??? Error using ==> mesh at 80 X, Y, Z, and C cannot be complex. ... Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral/answers/33474-convert-complex-matrix-to-3d-plot#answer_42109
Top answer
1 of 1
3

First, define your complex function as a function of (Re(x), Im(x)). In complex analysis, you can decompose any complex function into its real parts and imaginary parts. In other words:

F(x) = Re(x) + i*Im(x) 

In the case of a two-dimensional grid, you can obviously extend to defining the function in terms of (x,y). In other words:

F(x,y) = Re(x,y) + i*Im(x,y) 

In your case, I'm assuming you'd want the 2D approach. As such, let's use I and J to represent the real parts and imaginary parts separately. Also, let's start off with a simple example, like cos(x) + i*sin(y) which is based on the very popular Euler exponential function. It isn't exact, but I modified it slightly as the plot looks nice.

Here are the steps you would do in MATLAB:

  1. Define your function in terms of I and J
  2. Make a set of points in both domains - something like meshgrid will work
  3. Use a 3D visualization plot - You can plot the individual points, or plot it on a surface (like surf, or mesh).

NB: Because this is a complex valued function, let's plot the magnitude of the output. You were pretty ambiguous with your details, so let's assume we are plotting the magnitude.

Let's do this in code line by line:

% // Step #1
F = @(I,J) cos(I) + i*sin(J);

% // Step #2
[I,J] = meshgrid(-4:0.01:4, -4:0.01:4);

% // Step #3
K = F(I,J);

% // Let's make it look nice!
mesh(I,J,abs(K));
xlabel('Real');
ylabel('Imaginary');
zlabel('Magnitude');
colorbar;

This is the resultant plot that you get:

Let's step through this code slowly. Step #1 is an anonymous function that is defined in terms of I and J. Step #2 defines I and J as matrices where each location in I and J gives you the real and imaginary co-ordinates at their matching spatial locations to be evaluated in the complex function. I have defined both of the domains to be between [-4,4]. The first parameter spans the real axis while the second parameter spans the imaginary axis. Obviously change the limits as you see fit. Make sure the step size is small enough so that the plot is smooth. Step #3 will take each complex value and evaluate what the resultant is. After, you create a 3D mesh plot that will plot the real and imaginary axis in the first two dimensions and the magnitude of the complex number in the third dimension. abs() takes the absolute value in MATLAB. If the contents within the matrix are real, then it simply returns the positive of the number. If the contents within the matrix are complex, then it returns the magnitude / length of the complex value.

I have labeled the axes as well as placed a colorbar on the side to visualize the heights of the surface plot as colours. It also gives you an idea of how high and how long the values are in a more pleasing and visual way.

As a gentle push in your direction, let's take a slice out of this complex function. Let's make the real component equal to 0, while the imaginary components span between [-4,4]. Instead of using mesh or surf, you can use plot3 to plot your points. As such, try something like this:

F = @(I,J) cos(I) + i*sin(J);

J = -4:0.01:4;
I = zeros(1,length(J));

K = F(I,J);
plot3(I, J, abs(K));
xlabel('Real');
ylabel('Imaginary');
zlabel('Magnitude');
grid;

plot3 does not provide a grid by default, which is why the grid command is there. This is what I get:

As expected, if the function is purely imaginary, there should only be a sinusoidal contribution (i*sin(y)).

You can play around with this and add more traces if you need to.

Hope this helps!

🌐
Unsw
maths.unsw.edu.au › sites › default › files › MatlabSelfPaced › lesson10 › MatlabLesson10_Complex.html
MATLAB Lesson 10 - Plotting complex numbers
Define the complex number z = 3 + 2i and plot it as a point on the complex plane. The first argument is the real part, the second the imaginary part · Plotting the real and imaginary parts separately will work. Matlab recognises the input is a complex number and does some of the work for you.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 481647-plot-3d-matrix-with-complex-values
Plot 3D matrix with complex values - MATLAB Answers - MATLAB Central
September 23, 2019 - Plot 3D matrix with complex values. Learn more about matrix, 3d plots, matrix 3d, stft result, complex
Find elsewhere
🌐
YouTube
youtube.com › watch
Plotting Complex Functions - Matlab for Non-Believers - YouTube
Some equations, f(x), have complex roots that you can't see by just plotting using only real values of x. Here's how to plot complex roots of a function. C...
Published   October 23, 2018
🌐
MathWorks
mathworks.com › matlabcentral › answers › 554767-matlab-command-for-plotting-complex-number
Matlab command for plotting complex number? - MATLAB Answers - MATLAB Central
June 25, 2020 - plot(real(x) and plot(imag(x) ,both plots show up separately real and imaginary parts,but i want to see complex number (x) When i use only plot(x), although i get a plot, but i also get a warning that only real part is being plotted ... https://www.mathworks.com/matlabcentral/answers/554767-matlab-command-for-plotting-complex-number#comment_1909465
🌐
MathWorks
mathworks.com › matlabcentral › answers › 498947-plot-vector-using-complex-numbers
plot vector using complex numbers - MATLAB Answers - MATLAB Central
January 5, 2020 - I have array or matrix of complex numbers like this; [-3+4i;-2+5i;1+3i;6+2i;-1-8i] I want connect each point of abow matrix with 0+0i using line arrow (vector). Arrow starts form 0+0i and ends at...
🌐
Matrixlab-examples
matrixlab-examples.com › complex-numbers.html
Complex Numbers - how to plot them in numerical software
This is an intro to coding complex numbers in Matlab. The unit of imaginary numbers is root of -1 and is generally designated by the letter i (or j). Many laws which are true for real numbers are true for complex ones as well...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 507307-plotting-a-complex-matrix
Plotting a complex matrix - MATLAB Answers - MATLAB Central
February 24, 2020 - Hello! I have got a matrix with complex numbers (a+bi) which represents the amplitude and angle. I would like to create a plot (3D) with one axis for the frequency and another axis for the time d...
Top answer
1 of 2
2

Technically speaking, those are only circles if x and y axes are scaled equally. That is because scatter always plots circles, independently of the scales (and they remain circles if you zoom in nonuniformly. + you have the problem with the line, which should indicate the angle...

You can solve both issues by drawing the circles:

function plotCirc(x,y,r,theta)
% calculate "points" where you want to draw approximate a circle
ang = 0:0.01:2*pi+.01; 
xp = r*cos(ang);
yp = r*sin(ang);
% calculate start and end point to indicate the angle (starting at math=0, i.e. right, horizontal)
xt = x + [0 r*sin(theta)];
yt = y + [0 r*cos(theta)];
% plot with color: b-blue
plot(x+xp,y+yp,'b', xt,yt,'b'); 
end

having this little function, you can call it to draw as many circles as you want

x = [1 2 3];
y = [2 2 4];
radius = [1 1.2 2.2];
theta = [-pi 0 pi];

figure
hold on
for i = 1:length(x)
    plotCirc(x(i),y(i),radius(i),theta(i))
end

2 of 2
0

I went back over scatter again, and it looks like you can't get that directly from the function. Hopefully there's a clean built-in way to do this, and someone else will chime in with it, but as a backup plan, you can just add the lines yourself.

You'd want a number of lines that's the same as the length of your coordinate set, from the center point to the edge at the target angle, and fortunately 'line' does multiple lines if you feed it a matrix.

You could just tack this on to the end of your code to get the angled line:

x_lines = [x; x + radius.*cos(theta)];
y_lines = [y; y + radius.*sin(theta)];
line(x_lines, y_lines, 'Color', 'b')

I had to assign the color specifically, since otherwise 'line' makes each new line cycle through the default colors, but that also means you could easily change the line color to stand out more. There's also no center dot, but that'd just be a second scatter plot with tiny radius. Should plot most of what you're looking for, at least.

(My version of Matlab is old enough that scatter behaves differently, so I can only check the line part, but they have the right length and location.)

Edit: Other answer makes a good point on whether scatter is appropriate here. Probably better to draw the circle too.

🌐
Brown University
cfm.brown.edu › people › dobrush › am33 › Matlab › intro › complex0.html
MATLAB TUTORIAL for the First Course: Complex numbers
February 27, 2026 - In the latter set, the first coordinate ... as points z = x + jy using the x-axis as the real axis and y-axis as the imaginary axis is referred to as an Argand diagram....