How to assign specific colors to every quiver?

42 visualizaciones (últimos 30 días)
Thomas Schlatter
Thomas Schlatter el 17 de Oct. de 2019
Comentada: Thomas Schlatter el 17 de Oct. de 2019
Hi,
I would like to assign specific colors to my quiver plot. There are 13 quivers and i would assign to it 13 colors to reproduce it in a further iteration.
So my matrix A is [13x2], u and v are [13,1] and the color matrix col is [13x3].
The code should looke somehow like this but quiver doesn't accept a color matrix:
h(t)= quiver(A(:,1),A(:,2),u,v,1000,'color',col);
Is there a simple solution for this problem?
Thank you!

Respuestas (2)

darova
darova el 17 de Oct. de 2019
You can manually assign color to each vector
clc,clear
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
h = quiver(x,y,u,v);
% exctract data of vectors
h1 = get(h,'children');
x1 = get(h1(1),'xdata'); % arrowline
y1 = get(h1(1),'ydata');
x2 = get(h1(2),'xdata'); % arrowhead
y2 = get(h1(2),'ydata');
pause(0.2)
k = 0;
hold on
for i = 1:length(x1)/3
color = rand(1,3);
ii = (1:3) + (i-1)*3;
plot(x1(ii),y1(ii),'color',color)
plot(x2(ii+k),y2(ii+k),'color',color)
k = k + 1;
end
hold off
  3 comentarios
darova
darova el 17 de Oct. de 2019
What length of H vector?
Thomas Schlatter
Thomas Schlatter el 17 de Oct. de 2019
H is a '1x1 Quiver'.

Iniciar sesión para comentar.


Guillaume
Guillaume el 17 de Oct. de 2019
I can't remember if quiver did have children before R2014b (when the graphics system changed drastically) but since R2014b it does not (unless it has datatips, in which case the children are just the datatips).
It's not possible to access the individual arrows in a single quiver plot, at least in a documented way, and therefore it's not possible to change the colour of individual arrows.
You're left with making a single quiver call for each arrow (which may be slow) or searching on the FileExchange for an alternative implementation, e.g. this, this or this and probably more. Note that some of these functions (e.g. the first one) may use unsupported ways of accessing the quivers, which may not work in future matlab versions.
  1 comentario
Thomas Schlatter
Thomas Schlatter el 17 de Oct. de 2019
Okey, yes I use R2019a.
Thanks I'll take a look at it.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by