PROBLEM WITH QUIVER ARROW SIZE

46 次查看(过去 30 天)
francois heslot
francois heslot 2021-10-28
回答: Adam Danz 2023-8-27
Hello,
I am encountering a problem with arrows aspect ratio:
clf;
hold on;
load('Problem with Quiver.mat'); % load A and B , which are both 5743 X 1 double arrays
scatter(A, B, 1,'.'); % '1' is the marker size
DiffA= diff(A);
DiffB= diff(B);
quiver(A(1:1000:end-1),B(1:1000:end-1),DiffA(1:1000:end), DiffB(1:1000:end)); % step of 1000 to reduce the number of arrows plotted
title('Silly arrow size !')
%quiver(A(1:1000:end-1),B(1:1000:end-1),DiffA(1:1000:end), DiffB(1:1000:end),'MaxHeadSize', 1.e-4);
%title('Better arrow size, but silly aspect ratio for arrows (does not look as arrows, unless zoomed-in!')
% BELOW: 1st plot (no markerSize specif): the arrows are much too large.
% BELOW: MarkerSize specified: But the aspect ratio of the arrows is not
% correct! (the "arrow heads" apear as near-vertical lines, because their aspect ratio is not correct.
% An arrow "look" is only obtained locally if appropriately zooming-in horizontally.
I have NOT found the correct Quiver parameter set that would allow a reasonable display of the arrows on my graph.
HELP !
  1 个评论
Pai-Feng Teng
Pai-Feng Teng 2023-8-26
i am on the same boat with the same problem.I tried both quiver and annotation for marking out the direction of the loop
It seems like the quiver is nearly useless if the x-axis and y-axris aspect ratio is too high. It can be used if the aspect ratio of the x-axis and y-axis are close
I tried annotation arrowhead but it is just invisible

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2023-8-27
The problem
The quality of arrows produced by quiver is poor in highly skewed data aspect ratios.
In many cases equating the data aspect ratio using axis equal will create better looking arrows but if the data aspect ratio is sufficiently skewed, it will trade one problem for another, tiny or compressed arrows.
For a demonstration, here's @francois heslot's quiver plot with and without setting axis equal
load('Problem with Quiver.mat');
DiffA= diff(A);
DiffB= diff(B);
figure()
tiledlayout(2,1)
ax1 = nexttile();
quiver(A(1:1000:end-1),B(1:1000:end-1),DiffA(1:1000:end), DiffB(1:1000:end));
title('Default')
ax2 = nexttile();
copyobj(ax1.Children, ax2)
box on
axis equal
title('"axis equal"')
I recently explained what's going on in a comment in another thread but I'll recap here. If you look at the distribution of U and V values in quiver(x,y,u,v) which are the horizontal and vertical components of the vectors, you'll see
  1. both are small, centered around 0
  2. the vertical components tend to be much smaller than the horizontal components, by 4 orders of magnitude
figure
tiledlayout(2,1)
nexttile
histogram(DiffA(1:1000:end))
title('Horizontal component')
nexttile
histogram(DiffB(1:1000:end))
title('Vertical component')
Solution space
There isn't a quick and easy solution to this, assuming axis equal isn't suitable.
If you're OK with removing or replacing the arrowheads, you could turn the arrowheads off and place a marker at the tail or head of the arrows. Unlike arrowheads, markers do not use data aspect ratio.
Placing markers at the head require MATLAB R2022a or later.
In this demo, I chose a 'o' marker.
figure
tiledlayout(2,1)
nexttile()
quiver(A(1:1000:end-1),B(1:1000:end-1),DiffA(1:1000:end), DiffB(1:1000:end), 'o',...
'ShowArrowHead','off');
title('Marker at the tail')
nexttile()
quiver(A(1:1000:end-1),B(1:1000:end-1),DiffA(1:1000:end), DiffB(1:1000:end), 'o',...
'ShowArrowHead','off', ...
'Alignment', 'head'); % R2022a or later
title('Marker at the head')

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by