Why are the data points not being correctly colored to scale in my quiver plot?
1 回表示 (過去 30 日間)
古いコメントを表示
I want to create a quiver plot that can descibe a flow field with particle angle and velocity. I want to show the magnitude of the velocity field by colorizing each quiver-point with a color from a scale bar.
The issue I am facing is that some of the arrows are not correctly colored. For example, the yellow arrow in the attached image should represent the fastest moving particle and should be colored red to describe it's velocity of 59.56 mm/s. However right now it is being represented in yellow and I do not know why. All velocites are being normalized and compared to the maximum velocity value within the variable "velocities".
Thanks for the help! The code can be seen below.
% Acoustic Streaming Particle Tracking in Pressurized Conditions
% Hydrostatic Conditions
% h = 0 ft
clear all
clc
%% Particle Mapping in Crossflow Effects
ArrowLength = 300;
ArrowHeadSize = 5;
ArrowLineWidth = 1.5; % Adjust this value to change the line width of the arrows
ArrowScale = 1; % Adjust this value to change the size or scale of the arrows
% Distance from tip - 500 um
position500_1 = [-500, 500]; % x and y coordinates of arrow 1
angle500_1 = 360; % angle in degrees for arrow 1
velocity500_1 = 3.255569464; % velocity value for arrow 1
position500_2 = [0, 500]; % x and y coordinates of arrow 2
angle500_2 = 93.168; % angle in degrees for arrow 2
velocity500_2 = 59.56398362; % velocity value for arrow 2
position500_3 = [500, 500]; % x and y coordinates of arrow 3
angle500_3 = 190.248; % angle in degrees for arrow 3
velocity500_3 = 4.232935719; % velocity value for arrow 3
position500_4 = [-1000, 500]; % x and y coordinates of arrow 4
angle500_4 = 360; % angle in degrees for arrow 4
velocity500_4 = 2.313458035; % velocity value for arrow 4
position500_5 = [1000, 500]; % x and y coordinates of arrow 5
angle500_5 = 184.236; % angle in degrees for arrow 5
velocity500_5 = 2.284196058; % velocity value for arrow 5
% Distance from tip - 1000 um
position1000_1 = [-500, 1000]; % x and y coordinates of arrow 1
angle1000_1 = 105.427; % angle in degrees for arrow 1
velocity1000_1 = 6.675189766; % velocity value for arrow 1
position1000_2 = [0, 1000]; % x and y coordinates of arrow 2
angle1000_2 = 93.36; % angle in degrees for arrow 2
velocity1000_2 = 20.93672533; % velocity value for arrow 2
position1000_3 = [500, 1000]; % x and y coordinates of arrow 3
angle1000_3 = 81.254; % angle in degrees for arrow 3
velocity1000_3 = 5.836827773; % velocity value for arrow 3
position1000_4 = [-1000, 1000]; % x and y coordinates of arrow 4
angle1000_4 = 360; % angle in degrees for arrow 4
velocity1000_4 = 0.781474674; % velocity value for arrow 4
position1000_5 = [1000, 1000]; % x and y coordinates of arrow 5
angle1000_5 = 199.44; % angle in degrees for arrow 5
velocity1000_5 = 1.565790925; % velocity value for arrow 5
% Collecting the velocities from all data points
velocities = [velocity500_1, velocity500_2, velocity500_3, velocity500_4, velocity500_5, ...
velocity1000_1, velocity1000_2, velocity1000_3, velocity1000_4, velocity1000_5];
% Plotting the arrows
figure; hold on;
% 500 um
plotArrows(position500_1, angle500_1, velocity500_1, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_2, angle500_2, velocity500_2, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_3, angle500_3, velocity500_3, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_4, angle500_4, velocity500_4, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_5, angle500_5, velocity500_5, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
% 1000 um
plotArrows(position1000_1, angle1000_1, velocity1000_1, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_2, angle1000_2, velocity1000_2, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_3, angle1000_3, velocity1000_3, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_4, angle1000_4, velocity1000_4, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_5, angle1000_5, velocity1000_5, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
hold off;
axis equal;
xlim([-1500, 1500]);
ylim([-0, 4500]);
title('Acoustic Streaming Particle Tracking');
xlabel('X-coordinate');
ylabel('Y-coordinate');
% Define the getColor function
function color = getColor(velocity, velocities, maxVelocity)
colormap('jet');
c = colorbar;
caxis([min(velocities), maxVelocity]); % Adjusted to include min(velocities)
color = colormap(c);
color = interp1(linspace(min(velocities), maxVelocity, size(color, 1)), color, velocity);
end
% Define the plotArrows function
function plotArrows(position, angle, velocity, velocities, maxVelocity, ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth)
quiver(position(1), position(2), ArrowScale * ArrowLength * cosd(angle), ArrowScale * ArrowLength * sind(angle), ...
'Color', getColor(velocity, velocities, maxVelocity), 'MaxHeadSize', ArrowHeadSize, 'LineWidth', ArrowLineWidth);
end
0 件のコメント
回答 (1 件)
Voss
2023 年 7 月 14 日
See the change below in getColor.
% Acoustic Streaming Particle Tracking in Pressurized Conditions
% Hydrostatic Conditions
% h = 0 ft
clear all
clc
%% Particle Mapping in Crossflow Effects
ArrowLength = 300;
ArrowHeadSize = 5;
ArrowLineWidth = 1.5; % Adjust this value to change the line width of the arrows
ArrowScale = 1; % Adjust this value to change the size or scale of the arrows
% Distance from tip - 500 um
position500_1 = [-500, 500]; % x and y coordinates of arrow 1
angle500_1 = 360; % angle in degrees for arrow 1
velocity500_1 = 3.255569464; % velocity value for arrow 1
position500_2 = [0, 500]; % x and y coordinates of arrow 2
angle500_2 = 93.168; % angle in degrees for arrow 2
velocity500_2 = 59.56398362; % velocity value for arrow 2
position500_3 = [500, 500]; % x and y coordinates of arrow 3
angle500_3 = 190.248; % angle in degrees for arrow 3
velocity500_3 = 4.232935719; % velocity value for arrow 3
position500_4 = [-1000, 500]; % x and y coordinates of arrow 4
angle500_4 = 360; % angle in degrees for arrow 4
velocity500_4 = 2.313458035; % velocity value for arrow 4
position500_5 = [1000, 500]; % x and y coordinates of arrow 5
angle500_5 = 184.236; % angle in degrees for arrow 5
velocity500_5 = 2.284196058; % velocity value for arrow 5
% Distance from tip - 1000 um
position1000_1 = [-500, 1000]; % x and y coordinates of arrow 1
angle1000_1 = 105.427; % angle in degrees for arrow 1
velocity1000_1 = 6.675189766; % velocity value for arrow 1
position1000_2 = [0, 1000]; % x and y coordinates of arrow 2
angle1000_2 = 93.36; % angle in degrees for arrow 2
velocity1000_2 = 20.93672533; % velocity value for arrow 2
position1000_3 = [500, 1000]; % x and y coordinates of arrow 3
angle1000_3 = 81.254; % angle in degrees for arrow 3
velocity1000_3 = 5.836827773; % velocity value for arrow 3
position1000_4 = [-1000, 1000]; % x and y coordinates of arrow 4
angle1000_4 = 360; % angle in degrees for arrow 4
velocity1000_4 = 0.781474674; % velocity value for arrow 4
position1000_5 = [1000, 1000]; % x and y coordinates of arrow 5
angle1000_5 = 199.44; % angle in degrees for arrow 5
velocity1000_5 = 1.565790925; % velocity value for arrow 5
% Collecting the velocities from all data points
velocities = [velocity500_1, velocity500_2, velocity500_3, velocity500_4, velocity500_5, ...
velocity1000_1, velocity1000_2, velocity1000_3, velocity1000_4, velocity1000_5];
% Plotting the arrows
figure; hold on;
% 500 um
plotArrows(position500_1, angle500_1, velocity500_1, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_2, angle500_2, velocity500_2, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_3, angle500_3, velocity500_3, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_4, angle500_4, velocity500_4, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position500_5, angle500_5, velocity500_5, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
% 1000 um
plotArrows(position1000_1, angle1000_1, velocity1000_1, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_2, angle1000_2, velocity1000_2, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_3, angle1000_3, velocity1000_3, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_4, angle1000_4, velocity1000_4, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
plotArrows(position1000_5, angle1000_5, velocity1000_5, velocities, max(velocities), ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth);
hold off;
axis equal;
xlim([-1500, 1500]);
ylim([-0, 4500]);
title('Acoustic Streaming Particle Tracking');
xlabel('X-coordinate');
ylabel('Y-coordinate');
% Define the getColor function
function color = getColor(velocity, velocities, maxVelocity)
color = colormap('jet');
c = colorbar;
caxis([min(velocities), maxVelocity]); % Adjusted to include min(velocities)
% color = colormap(c);
color = interp1(linspace(min(velocities), maxVelocity, size(color, 1)), color, velocity);
end
% Define the plotArrows function
function plotArrows(position, angle, velocity, velocities, maxVelocity, ArrowLength, ArrowScale, ArrowHeadSize, ArrowLineWidth)
quiver(position(1), position(2), ArrowScale * ArrowLength * cosd(angle), ArrowScale * ArrowLength * sind(angle), ...
'Color', getColor(velocity, velocities, maxVelocity), 'MaxHeadSize', ArrowHeadSize, 'LineWidth', ArrowLineWidth);
end
参考
カテゴリ
Help Center および File Exchange で Vector Fields についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!