Skip to content

Commit daa9d66

Browse files
committed
Merge pull request #71 from jnj16180340/bug_2d-quiver-plots-arent-showing-arrows
2d quiver plots have arrowheads
2 parents d44d465 + 100f39b commit daa9d66

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

plotly/plotlyfig_aux/handlegraphics/updateQuiver.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,47 @@
8888

8989
%-------------------------------------------------------------------------%
9090

91+
%-quiver barbs-%
92+
if isHG2()
93+
% 'MaxHeadSize' scalar, matlab clips to 0.2 in r2014b
94+
maxheadsize = quiver_data.MaxHeadSize;
95+
% barb angular width, not supported by matlab
96+
head_width = deg2rad(17.5);
97+
for n = 1:length(xdata)
98+
% length of arrow
99+
l = norm([0.1*udata(n), 0.1*vdata(n)]);
100+
101+
% angle of arrow
102+
phi = atan2(vdata(n),udata(n));
103+
104+
% make barb with specified angular width, length is prop. to arrow
105+
barb = [...
106+
[-maxheadsize*l*cos(head_width), maxheadsize*l*sin(head_width)]; ...
107+
[0, 0]; ...
108+
[-maxheadsize*l*cos(head_width), -maxheadsize*l*sin(head_width)]; ...
109+
[nan, nan]; ...
110+
]';
111+
112+
% affine matrix: rotate by arrow angle and translate to end of arrow
113+
barb_transformation = affine2d([...
114+
[cos(phi), sin(phi), 0]; ...
115+
[-sin(phi), cos(phi), 0]; ...
116+
[xdata(n) + 0.1*udata(n), ydata(n) + 0.1*vdata(n), 1];
117+
]);
118+
119+
% place barb at end of arrow
120+
barb = transformPointsForward(barb_transformation, barb')';
121+
122+
% add barb to plot data, inserting is optimized in matlab >2010
123+
for col = 1:4
124+
obj.data{quiverIndex}.x(end+1) = barb(1,col); % point 1
125+
obj.data{quiverIndex}.y(end+1) = barb(2,col);
126+
end
127+
end
128+
end
129+
130+
%-------------------------------------------------------------------------%
131+
91132
%-scatter showlegend-%
92133
leg = get(quiver_data.Annotation);
93134
legInfo = get(leg.LegendInformation);

0 commit comments

Comments
 (0)