Using AlphaDataMapping in 3D Scatter Plots

6 views (last 30 days)
Isaac
Isaac on 28 Jan 2025
Answered: Raag on 30 Jan 2025
Hello,
I'm currently working on a Stewart platform project and have been working on a MATLAB program that assigns the platform a 3D workspace and calculates dexterity and manipulability of the platform at every point in the workspace. I'm running into challenges plotting my results, however. My goal is to plot the highest values of dexterity/manipulability in a bright, opaque green, to emphasize the machine's zone of highest performance. Then, I want to plot more moderate values in such a way that they gradually fade to an increasingly transparent red, to show the lower performance zones without obscuring the maximum performance zones of the workspace. Finally, I want the lowest performance zones to be absolutely transparent.
The issue I'm running into is scaling the alpha values of my points alongside my color map. I can't seem to find any way to vary alpha values throughout a scatter plot; only to set one single value for the whole plot. For reference, I'll attach my code for the plotting of my data as well as some images of what my figures look like now. If anyone knows how to use the 'AlphaDataMapping' value in the scatter3 command, that'd be super helpful!
My figures:
My code for plotting:
%% Dexterity Scatter Plot
% First, a custom color map
map = [1 1 1;
0.3 0 0;
0.4 0.2 0;
0.5 0.4 0;
0.5 0.6 0;
0.4 0.8 0;
0.3 1.0 0];
% Next, an alpha map for making lower values transparent
alphamap = [0; 1];
figure(1)
scatter3(X, Y, Z, 36, DEXtensor, 'filled', 'AlphaDataMapping','scaled','Alphadata',alphamap);
colormap(map); % Modify colormap
colorbar; % Show the colorbar to map values to colors
axis equal; % Ensure equal scaling on all axes
title('3D Visualization of Dexterity');
xlabel('X, inches');
ylabel('Y, inches');
zlabel('Z, inches');
% Manipulability Scatter Plot
figure(2)
scatter3(X, Y, Z, 36, MANItensor, 'filled', 'AlphaDataMapping','scaled', 'Alphadata', alphamap);
colormap(map); % Modify colormap
colorbar; % Show the colorbar to map values to colors
axis equal; % Ensure equal scaling on all axes
title('3D Visualization of Manipulability');
xlabel('X, inches');
ylabel('Y, inches');
zlabel('Z, inches');

Answers (1)

Raag
Raag on 30 Jan 2025
Hi Issac,
To achieve the desired effect, we need to ensure that the 'AlphaData' property in the ‘scatter3’ function is set correctly to map the alpha values based on your data. We can use normalized data to scale the alpha values. Here's an example of how we can modify your code:
% Let's normalize the data for alpha scaling
>> DEX_norm = (DEXtensor - min(DEXtensor)) / (max(DEXtensor) - min(DEXtensor));
>> MANI_norm = (MANItensor - min(MANItensor)) / (max(MANItensor) - min(MANItensor));
% Now, we'll create the Dexterity scatter plot
>> figure(1)
>> scatter3(X, Y, Z, 36, DEXtensor, 'filled', 'MarkerEdgeColor', 'k', ...
'AlphaData', DEX_norm, 'AlphaDataMapping', 'scaled');
>> colormap(map);
>> colorbar;
>> axis equal;
>> title('3D Visualization of Dexterity');
>> xlabel('X, inches');
>> ylabel('Y, inches');
>> zlabel('Z, inches');
>> grid on;
% Next, let's make the Manipulability scatter plot
>> figure(2)
>> scatter3(X, Y, Z, 36, MANItensor, 'filled', 'MarkerEdgeColor', 'k', ...
'AlphaData', MANI_norm, 'AlphaDataMapping', 'scaled');
>> colormap(map);
>> colorbar;
>> axis equal;
>> title('3D Visualization of Manipulability');
>> xlabel('X, inches');
>> ylabel('Y, inches');
>> zlabel('Z, inches');
>> grid on;
Output:
We can refer to the following documentation for reference:
scatter3:
Scatter Properties:

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!