how to control the transparency of quiver
72 ビュー (過去 30 日間)
古いコメントを表示
Is it able to adjust the transparency of each quiver? I tried to set the RGBA ([0 0 1 0.5]) of Quiver.Color, but it didn't work. This request is raised due to the impact of dense arrows; any suggestions would be appreciated.
2 件のコメント
Sam Chak
2025 年 8 月 30 日 6:51
Hi @lang
If your concern is about the dense arrows obscuring some trajectories or contours, it is preferable to adjust the number of arrows in the quiver plot rather than making the arrows semi-transparent. If possible, could you share the sample code for the quiver plot you are having issues with?
採用された回答
Sam Chak
2025 年 8 月 30 日 15:56
Hi @lang
Because you have sufficient and relatively large data, you can try the sampling method shown below:
load('S.mat', 'S');
% decide on the number of samples to take
percentage = 15; % (percentage of the data size)
numSamples1 = round(percentage/100*size(S.tri, 1));
numSamples2 = round(percentage/100*size(S.lon, 1));
numSamples3 = round(percentage/100*size(S.lat, 1));
numSamples4 = round(percentage/100*size(S.hs, 1));
numSamples5 = round(percentage/100*size(S.dir, 1));
% find the indices for equally spaced samples
idx1 = round(linspace(1, size(S.tri, 1), numSamples1));
idx2 = round(linspace(1, size(S.lon, 1), numSamples2));
idx3 = round(linspace(1, size(S.lat, 1), numSamples3));
idx4 = round(linspace(1, size(S.hs, 1), numSamples4));
idx5 = round(linspace(1, size(S.dir, 1), numSamples5));
% extract the sampled data
sampledTri = S.tri(idx1, :);
sampledLon = S.lon(idx2, :);
sampledLat = S.lat(idx3, :);
sampledHs = S.hs( idx4, :);
sampledDir = S.dir(idx5, :);
% plot
figure;
trisurf(S.tri, S.lon, S.lat, S.hs, 'facecolor', 'interp', 'edgecolor', 'none');hold on;
q = quiver3(sampledLon, sampledLat, 99*ones(size(sampledLat)), cosd(sampledDir), sind(sampledDir), zeros(size(sampledLat)), 1);
q.Color = .8*[1 1 1];
q.Alignment = 'center';
view(2);
axis([114 123 8 12]);
その他の回答 (2 件)
Walter Roberson
2025 年 8 月 29 日 7:18
There is no documented way to set the quiver transparency.
0 件のコメント
Mathieu NOE
2025 年 8 月 29 日 7:28
hello
either you use your own alternative to plot arrows with transparency control (see the Fex)
or just simply put your quiver arrows in some light color (I know it's not the same as transparent)
[x,y] = meshgrid(-2:.2:2,-1:.15:1);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.15);
contour(x,y,z), hold on
q = quiver(x,y,px,py); hold off, axis image
q.Color = 0.75*[1 1 1]; % some light grey color
2 件のコメント
Mathieu NOE
2025 年 8 月 29 日 7:50
I just experimented with : 3D Quiver with volumized arrows - File Exchange - MATLAB Central
Just to show the idea , I made a quick and dirty modification inside the function arrow3D.m and added the FaceAlpha parameter for the surf plot.
the modified function is in attachment
with the original code , the demo plot shows like this :

now with the modified code you can get something like that : (FaceAlpha = 0.25 for both head and stem)

you could even change separately the transparency of the head and the stem (not sure it's really of any interest)
(FaceAlpha = 0.5 for head and 0.25 for stem)

code modification in arrow3d.m !
% hStem = surf(stemX, stemY, stemZ, 'FaceColor', colorCode, 'EdgeColor', 'none'); % original code
hStem = surf(stemX, stemY, stemZ, 'FaceColor', colorCode, 'EdgeColor', 'none','FaceAlpha', 0.25); % modified code with tranpaency control
hold on;
% hHead = surf(headX, headY, headZ, 'FaceColor', colorCode, 'EdgeColor', 'none'); % original code
hHead = surf(headX, headY, headZ, 'FaceColor', colorCode, 'EdgeColor', 'none','FaceAlpha', 0.25); % modified code with tranpaency control
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!