Problem with Y axis range in percentage
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290936/image.png)
0 commentaires
Réponses (1)
Michael Soskind
le 6 Mai 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
Hope that solves your question,
Michael
3 commentaires
Michael Soskind
le 7 Mai 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
le 7 Mai 2020
In general, 'YTick' and 'YLim' are what I would think you would need.
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!