Control quiver arrow head width vs height.

28 visualizzazioni (ultimi 30 giorni)
Patrick
Patrick il 12 Set 2024
Modificato: Sreeram il 16 Set 2024
Hi, I have a quiver plot where the arrow heads are incredibly wide by default, so I used "MaxHeadSize" to shrink them to a reasonable size. Also, the scaling behavior is set to 0 because I want them to connect the way they do currently. The downside is that now, instead of looking like arrowheads, they almost look like horizontal bars. I'm wondering if there is a way to control the head length independently of the head width.
  3 Commenti
Patrick
Patrick il 12 Set 2024
Modificato: Patrick il 12 Set 2024
The original code depends on data external to MATLAB (Matlab calls a C function which calls other stuff to generate the data).
What I can give is a simple way to reproduce the scaling issue:
` ` `
X = 10000*rand(1, 50);
Y = [50:-1:1];
%{----------------------------------------------------------%}
%{ Generate list of steps from each "X" to the next "1" %}
%{----------------------------------------------------------%}
C = {};
D = {};
count0 = 0;
for (n = 1:length( X ))
if (X(n) >=50)
C{n-count0} = n;
else
count0 = count0 + 1;
end
end
alpha = 1;
for (n = 1:length( Y ))
D{n} = C{alpha} - n;
if (n == C{alpha})
D{n} = 0;
end
end
Y = cell2mat(D);
Z = Y;
%{---------------------------%}
%{ Create U and V arrays %}
%{---------------------------%}
E = {};
F = {};
for ( n = 2:length(X) )
if (X(n) == 1)
E{n} = 0;
else
E{n} = X(n)-X(n-1);
end
end
U = cell2mat(E);
U(end+1) = 0;
for ( n = 1:length(X) )
if (Y(n) == 0)
F{n} = 0;
else
F{n} = -1;
end
end
V = cell2mat(F);
W = V;
%% Create plots
f = figure();
f.WindowState = "maximized";
%{-----------------------------------------%}
%{ Quiver plot 1 with labels and stuff %}
%{-----------------------------------------%}
Q2A = subplot(1, 2, 1);
q2a = quiver(Y, X, U, V, 0);
q2a.MaxHeadSize = 0.1;
q2a.Marker = "*";
%{-----------------------------------------%}
%{ Quiver plot 2 with labels and stuff %}
%{-----------------------------------------%}
Q2B = subplot(1, 2, 2);
q2b = quiver(Y, X, V, U, 0);
q2b.MaxHeadSize = 0.01;
q2b.Marker = "*";
` ` `

Accedi per commentare.

Risposte (1)

Sreeram
Sreeram il 16 Set 2024
Modificato: Sreeram il 16 Set 2024
Hi Patrick,
This is happening because the range of X- and Y-coordinates differ significantly. The arrow heads are scaled in relation to the range of axes.
Although I could not find any way to adjust arrow’s head length independent of head width, you can follow the workaround by the MathWorks Support Team here:
Here’s how I implemented it:
scale_factor = range(Y)/range(X);
q2b = quiver(Y, X*scale_factor, V, U*scale_factor, 0);
q2b.Marker = "*";
ytlbls=Q2B.YTickLabel;
ytlbls=cellfun(@(c)str2double(c)/scale_factor,ytlbls);
set(Q2B,'YTickLabel',ytlbls)
Here’s a comparison of before and after for the second subplot (which had arrows appearing as horizontal line):
Before
 Before
After
I hope it helps!

Categorie

Scopri di più su Vector Fields in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by