Problem with addlistener to xlim

6 views (last 30 days)
jvc
jvc on 27 Jul 2015
Commented: jvc on 30 Jul 2015
I have a routine which needs to execute automatically every time the axis limits change in a plot. I have accomplished this by adding a listener with a callback function which updates the plot as required:
addlistener(axhdl, 'YLim', 'PostSet', @yaxisrescale)
My problem is that this solution only seems to work in HG2 (2014B, Win7) when the axis scaling is set explicitly, as in:
ylim([0,1]);% callback is properly triggered
If ylim is called with the 'auto' option the callback function is not triggered even if the axis was rescaled as a result of the call to ylim.
ylim('auto');% callback is not triggered - even if the axis is rescaled as a result of the call
Can anybody explain why this is happening and even better how to guarantee that every time the axis limits are changed my callback will be triggered?

Accepted Answer

Tushar Sinha
Tushar Sinha on 30 Jul 2015
Edited: Tushar Sinha on 30 Jul 2015
Hi Jon,
It is my understanding that you wish to know why the callback is not triggered when the axis limits are changed using the "ylim('auto')" command in MATLAB R2014b. I also understand that you wish to know if there is a workaround to achieve this.
This behavior is as expected. When MATLAB R2014b is automatically calculating the limits, the limits frequently change several times as MATLAB inspects each member of the axes and updates the limits. Allowing listeners to be triggered during the automatic calculation (even if no listener was attached) would have caused performance degradation for all users (even if they are not using listeners), so the ability to trigger listeners with automatically calculated property value changes was disabled for performance reasons.
However, in MATLAB R2014a, the callback is triggered even when the ylim mode is set to "auto". If you have this version of MATLAB you can achieve the desired behavior. There are no workarounds as of now for MATLAB R2014b. I work for Mathworks and I have forwarded this feedback to the appropriate product team.
Thanks,
Tushar
  1 Comment
jvc
jvc on 30 Jul 2015
Tushar, Thanks for the information - I thought this behavior used to be different prior to 2014B but I was not certain. Do you know if there is some other property to which the listener could be pointed in order to assure that my callback would be triggered when the axes are updated via ylim('auto')? Thanks

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!