Plot values of a variable on a 2D cross section with changing colors
4 views (last 30 days)
Show older comments
VINAYAK VINAYAK
on 25 Jun 2021
Commented: VINAYAK VINAYAK
on 29 Jun 2021
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
on 25 Jun 2021
How you are points are? What data you have? In general a scatter or pcolor should work for you.
Accepted Answer
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 .
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','.')
I hope this helps.
Seungbum
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!