how to control the transparency of quiver

70 visualizzazioni (ultimi 30 giorni)
lang
lang il 29 Ago 2025 alle 6:28
Commentato: lang il 31 Ago 2025 alle 5:00
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 Commenti
Sam Chak
Sam Chak il 30 Ago 2025 alle 6:51
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?
lang
lang il 30 Ago 2025 alle 8:28
Of course, the source code was using m_map toolbox, so I simplified the following code to make it stand alone. As you can see the arrows around the coastline are too dense, so I have to think of other ways to solve this problem. At first, I wanted to adjust the transparency (but it was difficult to achieve), and now I plan to re-mesh it to reduce the number of arrows.
load('S.mat', 'S');
figure;
trisurf(S.tri, S.lon, S.lat, S.hs, 'facecolor', 'interp', 'edgecolor', 'none');hold on;
q = quiver3(S.lon, S.lat, 99*ones(size(S.lat)), cosd(S.dir), sind(S.dir), zeros(size(S.lat)), 1);
q.Color = .75*[1 1 1];
q.Alignment = 'center';
view(2);
axis([114 123 8 12]);

Accedi per commentare.

Risposta accettata

Sam Chak
Sam Chak il 30 Ago 2025 alle 15:56
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]);
  1 Commento
lang
lang il 31 Ago 2025 alle 5:00
Thanks. Because these points belong to an unstructure grid, this downsampling method seems less than ideal. I am considering interpolating them onto a regular grid (meshgrid), which is one way to address this issue.

Accedi per commentare.

Più risposte (2)

Walter Roberson
Walter Roberson il 29 Ago 2025 alle 7:18
There is no documented way to set the quiver transparency.

Mathieu NOE
Mathieu NOE il 29 Ago 2025 alle 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 Commenti
Mathieu NOE
Mathieu NOE il 29 Ago 2025 alle 7:50
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
lang
lang il 29 Ago 2025 alle 7:56
Thanks, it looks much better.

Accedi per commentare.

Tag

Prodotti


Release

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by