How to set 'ShowArrowHead' off in the legend of a quiver plot?

In a quiver plot, there is a way to turn off arrow head by setting 'ShowArrowHead' off.
However the setting is not inherent by the associated legend. How to turn off arrow head for quiver plot legend?

Réponses (1)

From my understanding you want to turn off the arrowhead from the quiver plot. For that you can set 'Marker' property of quiver to 'none'. Here is an example to illustrate it:
[X,Y] = meshgrid(-pi:pi/8:pi,-pi:pi/8:pi);
U = sin(Y);
V = cos(X);
q = quiver(X,Y,U,V);
q.ShowArrowHead = 'off';
q.Marker = 'none';

3 commentaires

You need to plot the legend in order to reproduce this problem.
Thanks to your trial, but it does not answer this question.
Oh you are not able to add legends on a quiver plot. There is no direct way to do so in the form of a legend. But as a workaround you can add an extra point to the data and then add a text label to the data to show as legend.
Here is an example which might help you:
% From the example, define initial quiver points
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
% Add an additional row of points at y=2.4
[X,Y] = meshgrid(0:0.2:2, 2.4);
% Define a reference arrow velocity 1 at x=0.2 and y=2.4
u_rf=zeros(1, length(X));
v_rf=zeros(1, length(X));
u_rf(1,2)=1;
% Draw quiver plot including the new row
figure;
quiver([X;x],[Y;y],[u_rf;u],[v_rf;v]);
% Add text label to plot
text(0.05,2.5,'Arrow scale: 1m/s')
% Add bounding box if needed
rectangle('Position', [0.025, 2.3, 0.55, 0.3])
Thanks for your answer. That's also my current solution that manually creates the legend.
I do have other layers of other plot features 'hold on'. So I am looking for a consistent way of generating legends for all features.
I am still looking for an automated solution given that a legend of a plot should always be updated with the plot features it represents. Apparently, it's a bug that the quiver plot allows the user to turn off 'ShowArrowHead' but this modification is not updated in the corresponding legend.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Produits

Version

R2020b

Question posée :

le 8 Juin 2021

Commenté :

le 3 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by