How can I adjust the colorbar scale in my contour plot?

5 views (last 30 days)
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
Unrecognized function or variable 'mu_w'.
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
Image Analyst
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
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.

Sign in to comment.

Accepted Answer

Epsilon
Epsilon on 4 Dec 2024
Edited: Epsilon on 4 Dec 2024
Hi Eleanore,
The color scaling should be automatically done based on the range of data in velocity_grid_gw and velocity_grid_w .
Still the colormap limits can be changed using 'clim' for better visual clarity. Attaching an exapmle code below:
gm = linspace(0, 0.1, 100)';
gm = repmat(gm, 1, 100);
imagesc(gm);
% Colormap limits between 0 to 1
clim([0 1]);
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
imagesc(gm);
% Colormap limits between 0 to 0.1
clim([0 0.1]);
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
Documentation link to clim (caxis in releases before R2022a): https://www.mathworks.com/help/matlab/ref/clim.html
Hope it helps!

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!