Search code examples
matlabmatlab-figuremeshmatlab-guide

how to add color bar to mesh plot in matlab


I have written below code to show density plot of discrete data and vector field together. The problem is that there is no color bar in mesh plot. I did search to add color bar but I couldn't find any useful solution. Do anyone knows how can one do that?

clear all;
close all;
[x,y] = meshgrid(52:0.001:53,57:0.001:58);
u = (x.*(-1+3.*(y).^2./((x).^2+(y).^2))./(x.^2+(y).^2).^(3/2));
v = v-((y-yy(i)).*(-1+3.*(y).^2./(x).^2+(y).^2))./(x.^2+y.^2).^(3/2));
[curlz,cav]= curl(x,y,u,v);
h=streamslice(x,y,u,v,0.5)
hold on
mesh(x,y,w)

Solution

  • I used the first example since your minimal example had errors.

    have you just tried

    mesh(x,y,w)
    colorbar('southoutside')
    

    source

    enter image description here