Change Axis of a 2D plot in which the numbers have a power

3 views (last 30 days)
Hello,
Figure 1 was obtained using meshgrid function. The problem now is that it was required to me to change the axis of the plot for a better understanding (center of the axis at the center of the domain). To get a little closer to this goal, I used the following code which produced figure 2:
set(gca,'XTick',[0.006:0.001:0.012])
set(gca,'XTickLabel',['-3';'-2';'-1';' 0';' 1';' 2';' 3'])
set(gca,'YTick',[0.006:0.001:0.012])
set(gca,'YTickLabel',['-3';'-2';'-1';' 0';' 1';' 2';' 3'])
The problem with this method is that the positive numbers are not centered and that I am unable to put the power 10^-3 on both axis.
Can anybody give me a hint or a better way to deal with this question?
Thank you very much!

Answers (1)

Star Strider
Star Strider on 12 Dec 2015
I don’t entirely understand what ‘not centred’ means. It would be helpful if you described what you want.
It would be easier to define the tick locations and tick labels using the linspace function rather than the colon operator in this particular situation. The advantage of linspace is that it allows you to easily specify the length of the vector returned, with a different ‘step’ increment between values.
I can understand your wanting to shift the x-axis location to centre it, but power is power. I would leave the y axis as it is. If you want the y-axis to be divided by 1000, you have to do that when you define your 'YTickLabel' values.
  2 Comments
Simao Nobrega
Simao Nobrega on 12 Dec 2015
Edited: Simao Nobrega on 12 Dec 2015
First of all, thank you for your answer.
When talking about centered positive numbers, my intention was to center the numbers with the tick lines, but the problem was solved when I used your suggestion (linspace). The following code produced figure 3:
set(gca,'XTick',[0.006:0.001:0.012]);
set(gca,'XTickLabel',linspace(-3/1000,3/1000,7))
set(gca,'YTick',[0.006:0.001:0.012]);
set(gca,'YTickLabel',linspace(-3/1000,3/1000,7))
Now I just want to give a power appearance like in figure 4. Is this possible?
Star Strider
Star Strider on 12 Dec 2015
My pleasure.
First, with respect to the axis labels, I would use the new round function to round them to E-3. If you don’t have it, you can use the ‘roundn’ anonymous function version that works the same way.
To get the axes with integer labels and the exponents labeled separately, multiply the axis tick labels by 1000 and use a text object to label the exponents. This would be something like:
roundn = @(x,n) round(x .* 10.^n)./10.^n; % Round ‘x’ To ‘n’ Digits, Emulates Latest ‘round’ Function
xtl = roundn(linspace(-3/1000,3/1000,7), 3);
ytl = roundn(linspace(-3/1000,3/1000,7), 3);
[X,Y] = meshgrid([0.006:0.001:0.012]);
M = 1-((X-0.01).^2 + (Y-0.009).^2); % Create Data
figure(1)
contourf(X,Y,M)
set(gca,'XTick',[0.006:0.001:0.012]);
set(gca,'XTickLabel',xtl*1E3)
text(0.0117, 0.0054, '\cdot10^3')
set(gca,'YTick',[0.006:0.001:0.012]);
set(gca,'YTickLabel',ytl*1E3)
text(0.006, 0.0123, '\cdot10^3')
It works with the sample code here. You may have to experiment with it in your code to get the result you want.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!