how to control the transparency of quiver

28 visualizaciones (últimos 30 días)
lang
lang el 29 de Ag. de 2025
Comentada: lang el 31 de Ag. de 2025
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 comentarios
Sam Chak
Sam Chak el 30 de Ag. de 2025
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 el 30 de Ag. de 2025
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]);

Iniciar sesión para comentar.

Respuesta aceptada

Sam Chak
Sam Chak el 30 de Ag. de 2025
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 comentario
lang
lang el 31 de Ag. de 2025
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.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 29 de Ag. de 2025
There is no documented way to set the quiver transparency.

Mathieu NOE
Mathieu NOE el 29 de Ag. de 2025
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 comentarios
Mathieu NOE
Mathieu NOE el 29 de Ag. de 2025
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 el 29 de Ag. de 2025
Thanks, it looks much better.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by