Problem with Y axis range in percentage

조회 수: 1 (최근 30일)
Jordan Michael Flynn
Jordan Michael Flynn 2020년 5월 6일
댓글: Michael Soskind 2020년 5월 7일
Hello, I am having problem with the range of my Y-axis. The range of my data is 50 to 100% but the setting of my Y-axis only allows for the value of each data to be capped at 75 for some reason. How do I get the graph to show data from 50-100% instead of being capped at 75 as shown in the picture below. Any help would be deeply appreciated.
Ebat(1)=18; %the battery rated capacity is 36kWh
Pgrid(1)=Pavg(1);
Pbat(1)=Plg(1)-Pgrid(1);
for i=2:length(Plg)
Ebat(i)=Ebat(i-1)-Pbat(i-1)/4; %battery estimator
if Ebat(i)>=Cbat_max||Ebat(i)<=0 %block used to avoid over-charge
Pgrid(i-1)=Plg(i-1); %block used to avoid over-discharge
Pbat(i-1)=0;
Ebat(i)=Ebat(i-1);
end
Pgrid(i)=Pavg(i);
Pbat(i)=Plg(i)-Pgrid(i);
end
SOC=(50/36)*Ebat+50;
k=[1:length(Plg)];
plot(k,SOC)
y_pct_lbl = [50 60 70 80 90 100]; % Desired Labels
yt_orig = get(gca, 'YTick'); % Original Y-Tick Values & Labels
yt_new = linspace(min(yt_orig), max(75), numel(y_pct_lbl)); % New Y-Tick Values
yt_lbl = regexp(sprintf('%d %%\n', y_pct_lbl), '\n', 'split'); % New Y-Tick Labels
set(gca, 'YTick',yt_new, 'YTickLabel',yt_lbl(1:end-1))
t=1:29664;
set(gca,'xtick',linspace(t(1),t(end),12))
month = {'Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May','Jun','Jul'};
xticklabels(month)

답변 (1개)

Michael Soskind
Michael Soskind 2020년 5월 6일
Hi Jordan,
Look like you have the following line in your code:
yt_new = linspace(min(yt_orig), max(75), numel(y_pct_lbl)); % New Y-Tick Values
max(75) seems to be the limiting factor here, you should be able to replace that with
yt_new = linspace(min(yt_orig), 100, numel(y_pct_lbl)); % New Y-Tick Values
Hope that solves your question,
Michael
  댓글 수: 3
Michael Soskind
Michael Soskind 2020년 5월 7일
In general, there is also the scaling that you perform in the following line of code:
SOC=(50/36)*Ebat+50;
Depending on the range of Ebat, this is what will give you the limits from the calculation. So if Ebat has a max of 36, that equation works well, if it has a max of 18, then you will get the range up to 75. Without the data, it is a bit hard to know if that scaling is causing this problem or not.
Michael Soskind
Michael Soskind 2020년 5월 7일
Also, it could be that you are looking for the more general solution that was provided here.
In general, 'YTick' and 'YLim' are what I would think you would need.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by