Contourf colorbar color range

35 次查看(过去 30 天)
Kerem Tug GOKCEK
Kerem Tug GOKCEK 2021-7-19
编辑: DGM 2021-7-19
Hello everybody,
I'm writing a code for my experimental data (for my MSc thesis). I plot my contours with no problem. However, I have a problem in colorbar setting. I want to adjust the ranges of colormap and I want the colormap to match with it. I couldn' do it. My part of the code is below:
figure
contourf(xq,yq,uq,[-0.0094 0 0.05 0.1 0.15])
caxis([-0.0094, 0.15])
c=colorbar
c.Ticks=[-0.0094 0 0.05 0.1 0.15]
I can arrange my colormap in contourf but I could not control my colorbar as I wanted. I require my colorbar to show the corresponding color in the map for the ranges I selected. If anyone helps, I would be so grateful.

回答(1 个)

DGM
DGM 2021-7-19
编辑:DGM 2021-7-19
If you want a discrete colormap with nonuniformly-spaced breakpoints, you're going to have to make one. You're probably using a colormap with 256 breakpoints when you want 4. If your breakpoints were evenly spaced, you could do colormap(jet(4)), but since they are arbitrarily spaced, you're probably going to have to make a colormap such that breakpoints are where you expect them to be.
On the other hand, if you can extend caxis such that the breakpoints are evenly spaced, then you can just use a regular colormap.
x = (0:100)/100;
y = x';
z = (0.15+0.0094)*(x+y)/2 -0.0094;
contourf(x,y,z,[-0.05 0 0.05 0.1 0.15])
caxis([-0.05, 0.15]);
colormap(parula(4));
c=colorbar;

类别

Help CenterFile Exchange 中查找有关 Color and Styling 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by