How to color a region of a plot
8 次查看(过去 30 天)
显示 更早的评论
How do I color the disk in the middle (where r<1) white over the imagesc but under the vectors so they are still visible. Alternatively, how do I omit this region from the imagesc.
x=linspace(-2,2,300);
y=linspace(-2,2,300);
x2=x.^2;
y2=x.^2;
xy=x.*y';
U=1;
a=1;
vx=U*a^2*(x2./(x2+y2').^2-y2'./(x2+y2'));
vy=U*a^2*(xy./(x2+y2').^2+xy./(x2+y2'));
r=sqrt(x2+y2');
vx(abs(r)<1)=0;
vy(abs(r)<1)=0;
imagesc(x,y,vx)
hold on
quiver(x(10:10:end),y(10:10:end),vx(10:10:end,10:10:end),vy(10:10:end,10:10:end),1.5,'k')
axis equal
xlim([-2 2])
ylim([-2 2])
0 个评论
采纳的回答
Dyuman Joshi
2023-10-18
编辑:Dyuman Joshi
2023-10-18
You can set the corresponding values to NaN and change the color of the NaN values to white (or rather transparent) -
x=linspace(-2,2,300);
y=linspace(-2,2,300);
x2=x.^2;
y2=x.^2;
xy=x.*y';
U=1;
a=1;
vx=U*a^2*(x2./(x2+y2').^2-y2'./(x2+y2'));
vy=U*a^2*(xy./(x2+y2').^2+xy./(x2+y2'));
r=sqrt(x2+y2');
vx(abs(r)<1)=NaN;
vy(abs(r)<1)=NaN;
h = imagesc(x,y,vx);
set(h, 'AlphaData', ~isnan(vx))
colorbar
hold on
quiver(x(10:10:end),y(10:10:end),vx(10:10:end,10:10:end),vy(10:10:end,10:10:end),1.5,'k')
axis equal
xlim([-2 2])
ylim([-2 2])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!