Plot values of a variable on a 2D cross section with changing colors

10 views (last 30 days)
I need to plot a variable(say the variable name is Fp) on the 2D cross section(X & Y coordinates of say a circle) . I need the Fp to change its color as it's value changes in the cross section( as shown in the figure). For eg. in the image it can be seen that the variable intensity increases as we move towards the circumferance. I have the values of Fp at X, Y. I just need to know how to plot it like this. Could you please direct me to the required function or procedure to do so?the same?
  1 Comment
KSSV
KSSV on 25 Jun 2021
How you are points are? What data you have? In general a scatter or pcolor should work for you.

Sign in to comment.

Accepted Answer

Seungbum Koo
Seungbum Koo on 25 Jun 2021
Hi
I understand that you want to plot a set of data points where you have z value at every .
As mentioned by KSSV in the comment, in MATLAB, there is a function called pcolor.
For example,
% Create x and y
x = linspace(-1, 1, 201);
y = x;
[xi, yi] = meshgrid(x,y);
% Calculate z for every x and y
zi = cos(xi*pi/2).^2.*cos(yi*pi/2).^2;
% Plot
pcolor(xi, yi, zi)
% If you want the plot to be in scale
axis image
% If you don't like to see the grid lines
shading flat
% If you want to see the color bar
colorbar
If you want the color map to be identical to what you posted, you can do
colormap jet
but I personally don't recommend it, because when printed in black and white, it is impossible to distinguish min and max.
If you want to write some words on the plot, you can use function called text. And if you are familiar with LaTeX syntax, you can also do that.
text(0,0,'$z=\cos\left(\frac{\pi}{2}x\right)^2\cos\left(\frac{\pi}{2}y\right)^2$', ...
'interpreter','latex','Color','w')
There is no straightforward way to draw arrows in MATLAB. There is annotation function, but it draws an arrow that is relative to the figure window, not the plot. If you try out the following, you'll see what I mean.
annotation('arrow',[0.5,0.75],[0.5,0.75])
There is a function called quiver, but it does not give you the control over the shape of the arrowhead. If you are OK with that, I recommend using quiver.
% If you don't do the following, the existing plot will be erase when
% quiver plots.
hold on
% start point is [x0, y0].
% end point is [x1, y1].
% The suntax for quiver is
% quiver(x0, y0, x1-x0, y1-y0)
quiver(0,0,.3,.6)
% If you want the arrow to have white dashed line
quiver(0,0,.3,.6,'--w')
% If you want to adjust the arrow head size
quiver(0,0,.3,.6,'--w','AutoScaleFactor',1.2) % default is 0.9
% If you want to have a dot at the start point
quiver(0,0,.3,.6,'--w','AutoScaleFactor',1.2,'Marker','.')
Please refer to the complete list of quiver properties for more adjustment options.
I hope this helps.
Seungbum

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!