Plotyy set limits y-axis but use whole axis
1 view (last 30 days)
Show older comments
I use matlab R2015b and try to plot date with plotyy. When I set the limits for the plot the axis doesn't adjust to it and I cannot see all the datapoints inside the limits. I want the axis labeling to include the datapoints from the whole range inbetween the limits.
I need to change the xaxis to the date and I changed everything to include it in a latex file.
I hope someone can help me.
Thanks

if true
% code
function plotForSpecial(x1,y1,x2,y2,xbound,bound1,bound2,ref, tstart, tend, titlePlot, FolderName)
%plotForSpecial is a function to plot the different graphs with no need of
%writing the code often
% Input
%x1, x2 xdata as datenumb
%y1, y2 ydata
%xbound as datenumb
%bound1, bound2, ydata for boundaries
%tstart startdate for the plot as date
%tend enddate for the plot as date
reset(gca);
reset(gcf);
%plot
[hAx,hLine1,hLine2]=plotyy(x1, y1, x2,y2);
grid on;
set(hAx(1),'YLim',[-0.2 0.2])
set(hAx(2),'YLim',[-1 1])
lgd = legend('Frequenzabweichung in Hz','Berechnete PRL als Faktor der angebotenen PRL');
set(lgd, 'Interpreter', 'latex');%, 'FontSize', 8);
%set to date
hAx(1).FontSize = 12;
hAx(2).FontSize = 12;
set(hAx(1),'xtick',[datenum(tstart):((datenum(tend)-datenum(tstart))/3):datenum(tend)]) %fixed ticks to 7 per plot
set(hAx(2),'xtick',[datenum(tstart):((datenum(tend)-datenum(tstart))/3):datenum(tend)])
datetick(hAx(1),'x',0,'keepticks')
datetick(hAx(2),'x',0,'keepticks')
%set limits
xlim(hAx(1),[datenum(tstart) datenum(tend)]);
xlim(hAx(2),[datenum(tstart) datenum(tend)]);
hAx(1).TickLabelInterpreter = 'latex';
hAx(2).TickLabelInterpreter = 'latex';
%label, title, gird
xlabel('Zeit', 'Interpreter', 'latex', 'FontSize', 12);
ylabel(hAx(1),'Abweichung der Netzfrequenz in Hz', 'Interpreter', 'latex', 'FontSize', 12);
ylabel(hAx(2),'PRL', 'Interpreter', 'latex', 'FontSize', 12);
grid on;
title(titlePlot, 'Interpreter', 'latex', 'FontSize', 12);
% References
hold(hAx(1), 'on');
plot(xbound, bound1,'b--', xbound, bound2,'b--', xbound, ref,'r');
%lgd = legend('Frequenzabweichung in Hz','Berechnete PRL als Faktor der angebotenen PRL', 'Totbandgrenze', 'Totbandgrenze','Referenzlinie');
%set(lgd, 'Interpreter', 'latex');
hold off;
set(gcf, 'PaperPositionMode', 'auto', 'Units', 'Centimeters', 'Position', [2 2 17.4 17.4/21*12]);
plot_name = strcat('SpecialAbruf',titlePlot);
%% Export print(gcf,fullfile(FolderName, plot_name), '-depsc')
end
end
Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!