Why the colour bar values are not representing the vectors on the plot?
3 views (last 30 days)
Show older comments
Hi please see the attached image I am trying to use the colour bar to represent the U and V values from the graph but it is not representing it. can you guys guide me how to process it. Below is my current code.
Code:
files = { 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\Data_Vector\Run 13-56-31.Adaptive PIV.6tvk0mbp\Export.6tvk0mbp.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_PIV\Data_Vector\Run 17-19-03.Adaptive PIV.6ul4ynyv\Export.6ul4ynyv.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_PIV\Data_Vector\Run 17-19-03.Adaptive PIV.6ul4ynyv\Export.6ul4ynyv.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_PIV\Data_Vector\Run 12-45-51.Adaptive PIV.6tskdx6a\Export.6tskdx6a.000000.csv'};
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,5}/1000;
Y = a{:,6}/1000;
U = a{:,9};
V = a{:,10};
quiver(X, Y, U, V, 10);
xlim([0.1 0.4])
ylim([0.1 0.4])
colorbar('AxisLocation','in')
hold on
end
legend('DataLaserSheet-D','DataLaserSheet-C','DataLaserSheet-B','DataLaserSheet-A')
0 Comments
Accepted Answer
DGM
on 5 Jan 2022
Edited: DGM
on 5 Jan 2022
Quiver plots and line plots do not use the colormap used by colorbar. You have to explicitly set both the axes 'colororder' and 'colormap' properties to the same map.
load('wind','x','y','u','v')
X = x(11:22,11:22,1);
Y = y(11:22,11:22,1);
hold on
quiver(X,Y,u(11:22,11:22,1),v(11:22,11:22,1));
quiver(X,Y,u(11:22,11:22,2),v(11:22,11:22,2));
quiver(X,Y,u(11:22,11:22,3),v(11:22,11:22,3));
quiver(X,Y,u(11:22,11:22,4),v(11:22,11:22,4));
colormap(get(gca,'colororder'))
colorbar
That said, that's really what the legend is for. In this case, the colorbar scale has no clear meaning.
Still, I'm not sure if that's what you're asking for. "I am trying to use the colour bar to represent the U and V values" might mean that you're trying to describe the vector fields using some solid color map (like pcolor() or something). If that's the case, you'll have to actually do that.
figure
hold on
pcolor(X,Y,hypot(u(11:22,11:22,1),v(11:22,11:22,1)));
quiver(X,Y,u(11:22,11:22,1),v(11:22,11:22,1));
shading interp
colormap(gray(256))
colorbar
Note that I only plotted one quiver plot and the pcolor() plot shows only the vector magnitude. Trying to put more things into the same plot should raise the question of how they're expected to be represented clearly.
If you want to represent the vector field (both components) with pcolor(), then you might want to look at this discussion:
5 Comments
DGM
on 6 Jan 2022
I'm glad that tool worked out. I was worried you might have issues with such a large dataset. Getting good visualization out of quiver plots is kind of maddening, as you can see.
More Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!