How can I adjust the colorbar scale in my contour plot?
Show older comments
I have a contour plot with a colorbar that is showing as all one color. I would like to adjust the plot so that the colors have more variation to better show the changes in the plot. Below is a screenshot of my contour plot,

And here is an example of what I'd like it to look like.

Below is my code. I've tried a lot of different things, but I'm not very strong in Matlab and could not figure out where I'm going wrong. Any help is appreciated!
for i = 1:100
velocity_grid_gw(i,:) = ((mu_w/mu_gw)*(u_surface/(h+((mu_w/mu_gw)*d)-d))).*y_gw(i); %m/s
velocity_grid_w(i,:) = (u_surface/(h+((mu_w/mu_gw)*d)-d)).*y_w(i)+u_surface-(u_surface/(h+((mu_w/mu_gw)*d)-d))*h; %m/s
end
fontsize = 16; %font size for plotting
figure
imagesc(x_gw,y_gw,velocity_grid_gw);
hold on
imagesc(x_w,y_w,velocity_grid_w);
hold off
xlabel('$x$ (m)','Interpreter','Latex','FontSize',fontsize);
ylabel('$y$ (m)','Interpreter','latex','FontSize',fontsize);
set(gca,'YDir','normal')
grid on
cbar = colorbar('peer',gca);
set(get(cbar,'title'),'String','$u$ (m/s)','Interpreter','Latex','fontsize',fontsize)
set(gca,'fontsize',fontsize)
3 Comments
Walter Roberson
on 4 Dec 2024
Note that the color scaling is going to be determined by min(min(velocity_grid_gw(:)),min(velocity_grid_w(:))) and the corresponding max() . The color scaling is not going to be determined individually for velocity_grid_gw and velocity_grid_w
Image Analyst
on 4 Dec 2024
Your code does not work. Please provide a working example (how did you get your plots?). Why are you trying to show one image on top of another without setting the opacity/transparency?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Walter Roberson
on 4 Dec 2024
We do not know that the images are overlayed. The two imagesc calls use different variables for XData and YData, so potentially those variables are configured so that the images are side by side. Maybe.
Accepted Answer
More Answers (0)
Categories
Find more on Colorbar 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!
