How to color a region of a plot

8 visualizaciones (últimos 30 días)
Sobhan
Sobhan el 18 de Oct. de 2023
Comentada: Dyuman Joshi el 18 de Oct. de 2023
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])

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 18 de Oct. de 2023
Editada: Dyuman Joshi el 18 de Oct. de 2023
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])
  2 comentarios
Sobhan
Sobhan el 18 de Oct. de 2023
Thanks! Works perfectly, and thanks for including the colorbar as well. Was wondering how to get that.
Dyuman Joshi
Dyuman Joshi el 18 de Oct. de 2023
You are welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Orange en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by