How do I change axes scale in a surface plot by a predefined factor?

조회 수: 88 (최근 30일)
Iron1759
Iron1759 2021년 1월 3일
답변: Iron1759 2021년 1월 14일
Hello,
I have a surface plot -
on x axis - [0,1,2.... 15];
on y axis - [0,1,2,...50];
I'd like to change the axes scale by multiply these two vector by a factor (different one on each axis), for exmaple by 12.5578 and thus changing only the axes lables.
I'm familair with XtickLabel and YTickLabel but I think it's less applicatble, mainly becaue this factor is not round.
Real life example - for instance when you want to change reperesntation from pixles to real units without changing the data.
Any thoughts?

채택된 답변

Iron1759
Iron1759 2021년 1월 14일
Thanks, it works..

추가 답변 (1개)

Mischa Kim
Mischa Kim 2021년 1월 3일
Iron, if it just about changing the labels simply use xticklabels(). See the example below:
x = linspace(-10,10,200);
y = cos(x);
plot(x,y)
xticklocs = [-3*pi -2*pi -pi 0 pi 2*pi 3*pi];
xticks(xticklocs);
myfac = 10; % this would be your 12.5578
xticklabels(cellstr(num2str(xticklocs'*myfac)));
  댓글 수: 4
Iron1759
Iron1759 2021년 1월 9일
I don't know if it's only me but I didn't quite get it.
xticklocs/yticklocs are both 1D arrays after 'conversion' from nanometers (that I want to present) to a different unit.
Then, I don't get a display of my surface (after I used meshgrid).
xticklabels(cellstr(num2str(x))); % 0:10:200
yticklabels(cellstr(num2str(y))); % 0:10:200
Multi_x = multiplier_x; % = ~11.93
Multi_y = multiplier_y; % = ~ 3.98
xticklocs = x./Multi_x;
yticklocs = y./Multi_y;
xticks(xticklocs);
yticks(yticklocs);
Mischa Kim
Mischa Kim 2021년 1월 10일
See this example:
x = linspace(-10,10,200);
y = cos(x);
figure(1)
plot(x,y)
xticklocs = [-3*pi -2*pi -pi 0 pi 2*pi 3*pi];
xticks(xticklocs);
figure(2)
plot(x,y)
xticklocs = -400:80:400; % these are the nice numbers
myfac = 400/(3*pi);
xticklabels(cellstr(num2str(xticklocs.')));
xticks(xticklocs/myfac);
If this does not help, share your code so I can provide specific input.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by