How to add colourmap to 2D vectorplot created by using quiver
10 次查看(过去 30 天)
显示 更早的评论
Hello all,
I have created 2D vector plot by using quiver i.e( quiver (x,y,u,v)), i am getting vecrot plot of 20*9 ( totally 180 vectors) . i have to add colours to this vector plot where colour of the plot represents the magnitude of vector at that index along with vectors in the plot with colour bar the end. kindly help me in this and any proper sources for learning the matlab as i am a beginner.
Thank in advance
0 个评论
回答(2 个)
Shubham Rawat
2021-1-25
Hi HariKrishna,
You may use this file to solve your problem:
You can download this file and run into your MATLAB. This contains a function quiverwcolorbar, which can colour the vector plot according to their vector magnitude.
Hope this helps!
darova
2021-2-4
Try this example
clc,clear
[x,y,z] = peaks(20); % generate data
[u,v] = gradient(z,1); % create u and v vectors
h = quiver(x,y,u,v); % display standard quiver
% extract each arrow separately
c = get(h,'children');
x1 = get(c(2),'xdata'); % arrow body
y1 = get(c(2),'ydata');
x2 = get(c(3),'xdata'); % arrow head
y2 = get(c(3),'ydata');
cmap = jet(200); % generate 200 colors
% color arrows according to Z values
F = scatteredInterpolant(x,y,z);
zmin = min(z(:));
k = max(z(:)) - min(z(:));
for i = 1:3:length(x1);
ii = (F(x1(i),y1(i))-zmin)/k*199; % scale Z value (0-199)
ii = round(ii)+1; % index of color
line(x1(i:i+2),y1(i:i+2),'color',cmap(ii)) % body
line(x2(i:i+2),y2(i:i+2),'color',cmap(ii)) % head
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!