Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:19+00:00 2026-05-25T12:42:19+00:00

I am generating a plot in real-time. I shift the x-axis by 30 seconds,

  • 0

I am generating a plot in real-time. I shift the x-axis by 30 seconds, every 30 seconds. This is all well and good, but my y-axis is auto-resizing itself to smaller than previously. Take a look below:

Plot before 30 second threshold - Y limits are [-1 1]

This is my data before we hit the 30 seconds and redraw the x-axis labels. I’m just plotting ±cos(t) right now, so my Y limits are [-1 1].

After 30 second threshold -  Y limits are [-0.8 0.5]

After the 30 seconds, I shift the axes over to start watching the plot generate on the time interval [30 60]. Notice that my Y limits have rescaled to [-0.8 0.5]. As time increases, the limits go back to [-1 1]. But I would like to have continuity between the previous 30 second snapshot and the current snapshot in time, i.e., limits should be [-1 1] immediately after hit the 30 second threshold.

Is there a way to keep the previous Y limits and still let them grow properly (i.e., if Y data goes over limits it’ll resize appropriately, automatically)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:42:20+00:00Added an answer on May 25, 2026 at 12:42 pm

    The y-axis limits will rescale automatically if the YLimMode of the axis is set to auto. Set it to manual to prevent this:

    >> set(gca, 'YLimMode', 'manual');
    

    In order to have the limits update automatically to appropriate values when the data on the plot is updated you could listen for updates to the line using an event listener. This approach requires you to update the plotted line by updating the line’s XData and YData properties. Create the line and listener:

    >> h = line('XData', [], 'YData', []);
    >> addlistener(h, 'YData', 'PostSet', @(src, evnt) set(evnt.AffectedObject.Parent, 'YLim', [min(evnt.AffectedObject.YData) max(evnt.AffectedObject.YData)]));
    

    The listener definition includes an anonymous function that uses the event properties to access the line’s parent (i.e. the axes) and set the y-axis limits to the minimum and maximum of the plotted y values. This function is executed when the YData property of the plotted line is updated.

    To see this in action, try the following:

    >> x = 1;
    >> y = cos(x);
    >> for ii = 2:1000
    x(end+1) = ii;
    y(end+1) = cosd(x(end));
    set(h, 'XData', x, 'YData', y);
    pause(0.01);
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For generating random string i written code like this But if the function is
I am looking for help with generating this plot from a sequence of ones
Generating normal columnar data in excel file is quite easy but does any one
When generating graphs and showing different sets of data it usually a good idea
Im generating a file to present to the user for download, but the server
I am generating text using this : for i in xrange(100): sys.stdout.write(alphabet[bisect.bisect(f_list, random.random()) -
Generating a random password is easy. but generating a batch is more difficult. public
I'm a bit lost on this one, I've tried messing around with geom_polygon but
Im generating a plain txt file from Physics editor. It contains all the vertices
I generating a string for my Primarykey column similar identity function. but its behavior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.