# Problem with Y axis range in percentage

4 views (last 30 days)
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) Michael Soskind on 6 May 2020
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
Michael

Jordan Michael Flynn on 7 May 2020
I already did that but it changes the range of the Y-axis from 50 to 75. it's no longer using the set range of 50 to 100%
Michael Soskind on 7 May 2020
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 on 7 May 2020
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.