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

33 Ansichten (letzte 30 Tage)
Eleanore
Eleanore am 4 Dez. 2024
Kommentiert: Eleanore am 6 Dez. 2024
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 Kommentare
Image Analyst
Image Analyst am 4 Dez. 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 am 4 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Epsilon
Epsilon am 4 Dez. 2024
Bearbeitet: Epsilon am 4 Dez. 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!

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by