简体   繁体   中英

Rescaling Vertical and Horizontal Axes

I am producing a series of figures of a world map. I wish to rescale the vertical and horizontal axes. At present, the vertical axis is from -80 to 80 (in increments of 20) and the horizontal axis is from 0 to 360 (in increments of 50).

I wish to set the vertical axis to be from -70 to 70 (in increments of 20) and the horizontal axis to be from 0 to 360 (but in increments of 30).

Here is a section of my code for the colour of the map, as well as arranging the colourbar.

function custom_map=mycolormap
blues = [linspace(0, 1, 100); 
         linspace(0, 1, 100); 
         linspace(1, 1, 100);]';
reds = [linspace(1, 1, 100);
        linspace(1, 0, 100); 
        linspace(1, 0, 100);]';
custom_map = [blues; reds]; 
caxis([-6,6]);
ylabel(colorbar, 'SSTA (°C)');

It is possible to do so using xlim, ylim, xticks and yticks. It seems to me that what you should do is insert the following lines at the end of your function:

xMin   = 0;
xMax   = 360;
xStep  = 30;
yMin   = -70;
yMax   = 70;
yStep  = 20;
xlim([xMin, xMax]);      % Sets the limit of the x axis
ylim([yMin, yMax]);      % Sets the limit of the y axis
xticks(xMin:xStep:xMax); % Sets the increments of the x axis
yticks(yMin:yStep:yMax); % Sets the increments of the y axis

As far as I've tried this should work. Feel free to follow different naming conventions for naming the variables but it is good practice to avoid magic numbers in your code especially since some of them will appear multiple times.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM