Contourf colorbar color range
35 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.

0 commentaires
Réponses (1)
DGM
le 19 Juil 2021
Modifié(e) : DGM
le 19 Juil 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;
0 commentaires
Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
