How to change xlim to specific range only?

조회 수: 2 (최근 30일)
ramya
ramya 2024년 8월 6일
댓글: dpb 2024년 8월 7일
a=xlsread('output1.xlsx','final graph');
xaxis=0:9;
yaxis=a(:,2);
yaxis1=a(:,3);
yaxis=a(:,4);
yaxis2=a(:,5);
figure
plot(xaxis,yaxis)
hold on
plot(xaxis,yaxis1)
hold on
plot(xaxis,yaxis2)
how to change xlim to specific to 0 :3:9 ylim to 30:30:300 how to insert data tips or markers at each point of xaxis
  댓글 수: 1
dpb
dpb 2024년 8월 6일
xlim, ylim set limits but specific ticks are via xticks, yticks. datatip does what it says it does...

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

답변 (2개)

dpb
dpb 2024년 8월 6일
a=readmatrix('output1.xlsx','Sheet','final graph'); % xlsread has been deprecated
cols2plot=[2:5]; % indices to columns wanting to plot
x=[0:height(a)-1]; % generalize instead of hardcoding magic numbers
hL=plot(x,a(:,cols2plot)); % plot is vectorized by columns; no need for repeating
XL=0; XH=9; XT=3; % limits, tick delta -- as data, not code
YL=30; YH=300; YT=30;
xlim([XL XH]); ylim([YL YH])
xticks([XL:XT:XH]); yticks([YL:YT:YH]);
grid on
  댓글 수: 3
Walter Roberson
Walter Roberson 2024년 8월 7일
xticks([0,3,5,9])
Unless you mean something like
text([0,3,5,9], a([1 4 6 10],cols2plot), ["0", "3", "5", "9"])
dpb
dpb 2024년 8월 7일
a=readmatrix('output1.xlsx','Sheet','final graph'); % xlsread has been deprecated
cols2plot=[2:5]; % indices to columns wanting to plot
x=[0:height(a)-1]; % generalize instead of hardcoding magic numbers
hL=plot(x,a(:,cols2plot)); % plot is vectorized by columns; no need for repeating
XL=0; XH=9; XT=3; % limits, tick delta -- as data, not code
YL=30; YH=300; YT=30;
xlim([XL XH]); ylim([YL YH])
xticks([XL:XT:XH]); yticks([YL:YT:YH]);
grid on
% add data tips although there's very little room
% this does the requested positions in X for the first line requested to be
% plotted; adding for the other lines would write over these...you don't
% have sufficient room for that much data on the plot...the location at 0
% is off the defined y-axis limits so doesn't show...
TX=[0 3 5 9];
for i=1:numel(TX)
%disp([i TX(i) find(x==TX(i)) a(x==TX(i),cols2plot(1))])
datatip(hL(1),TX(i),a(x==TX(i),cols2plot(1)));
end

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


Walter Roberson
Walter Roberson 2024년 8월 6일
how to change xlim to specific to 0 :3:9 ylim to 30:30:300
That is not possible. xlim() expects to be passed a limit method (such as "tight") or a limit mode (such as "manual"), or a two-element vector of type single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration
Under no circumstances will xlim accept the four element vector [0 3 6 9] which is what 0:3:9 would request.
You can ask for
xticks(0:3:9)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by