# Change colorbar axis values

21 vues (au cours des 30 derniers jours)
Ban le 18 Août 2023
Commenté : ProblemSolver le 18 Août 2023
Hi,
I am trying to convert my contour plot axes from degree to radian. Please suggest how do I do it? Particularly how do I change colorbar axes label from (0, 360) to (0, 2*pi) format.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

ProblemSolver le 18 Août 2023
xticks = [0 pi/2 pi 3*pi/2 2*pi];
xticklabels = {'0','π/2','π','3π/2','2π'};
set(gca,'XTick',xticks,'XTickLabel',xticklabels)
yticks = [0 pi/2 pi 3*pi/2 2*pi];
yticklabels = {'0','π/2','π','3π/2','2π'};
set(gca,'YTick',yticks,'YTickLabel',yticklabels)
c = colorbar;
c.Ticks = [0 pi/2 pi 3*pi/2 2*pi];
c.TickLabels = {'0','π/2','π','3π/2','2π'};
##### 2 commentairesAfficher AucuneMasquer Aucune
Ban le 18 Août 2023
Does not work.
ProblemSolver le 18 Août 2023
Because its not the whole code. I have given you just the places that you need understand and add in your current program.

Connectez-vous pour commenter.

### Plus de réponses (1)

Voss le 18 Août 2023
You need to scale the contour color data from (0,360) to (0,2*pi), i.e., convert from degrees to radians.
First, I make a contour of data in degrees spanning 0 to 360 (more or less):
% some random data
x = 1:10;
y = 1:20;
c = 360*rand(numel(y),numel(x));
figure
contour(x,y,c)
colorbar
clim([0 360]) % color-limits in degrees
Now, to make the colorbar in radians, simply convert the color data itself using deg2rad, and plot it as before:
figure
contour(x,y,c)
colorbar;
clim([0 2*pi]) % color-limits in radians
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Colormaps 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!

Translated by