How can I change the axis limit when I have 2 axes in my figure?

B
Brianna · Dec 3, 2020 · 2.3K views
Question
I have a figure with 2 axes: >> figure >> yyaxis left >> plot(1:10); >> yyaxis right >> plot(2:2:20); How can I change the y-limit of my left axis to be 0 to 5, but the right axis to be 5 to 10?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 20, 2026

You can use the "yyaxis" and "ylim" commands to set the y-limit for both axes:

 

>> figure
>> yyaxis left
>> plot(1:10);
>> yyaxis right
>> plot(2:2:20);
>>
>> f = gcf;
>> yyaxis left
>> ylim(f.Children, [0 5]);
>> yyaxis right
>> ylim(f.Children, [5 10]);
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!