Plot values of a variable on a 2D cross section with changing colors
6 ビュー (過去 30 日間)
古いコメントを表示
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?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/664865/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/664865/image.png)
1 件のコメント
KSSV
2021 年 6 月 25 日
How you are points are? What data you have? In general a scatter or pcolor should work for you.
採用された回答
Seungbum Koo
2021 年 6 月 25 日
Hi
I understand that you want to plot a set of data points where you have z value at every
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/665680/image.png)
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Vector Fields についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!