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!