How can I adjust the colorbar scale in my contour plot?
21 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2024-12-4
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
2024-12-4
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.
采纳的回答
Epsilon
2024-12-4
编辑:Epsilon
2024-12-4
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 White 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!