How to change xlim to specific range only?

38 次查看(过去 30 天)
ramya
ramya 2024-8-6,20:51
评论: dpb 2024-8-7,14:25
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

回答(2 个)

dpb
dpb 2024-8-6,21:39
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,4:56
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,14:25
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,20:58
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 中查找有关 Just for fun 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by