Contourf colorbar color range

35 visualizaciones (últimos 30 días)
Kerem Tug GOKCEK
Kerem Tug GOKCEK el 19 de Jul. de 2021
Editada: DGM el 19 de Jul. de 2021
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.

Respuestas (1)

DGM
DGM el 19 de Jul. de 2021
Editada: DGM el 19 de Jul. de 2021
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;

Categorías

Más información sobre Color and Styling en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by