MATLAB Answers

Resizing Callbacks with invisible figures

3 views (last 30 days)
aboharbf on 26 Jun 2019
Commented: aboharbf on 10 Jul 2019
I'm running into an issue where I've attached the following to a figure:
figHandle.SizeChangedFcn = @(src,event) set(src.Children(3),'Position',get(src.Children(end),'Position'));
The goal of this is to move a specific element (in this case, a legend), in line with a second element (another legend for the primary axes). If relevant, the idea is to move the legend of an invisible axes in line with the legend already associated with the visible one. I have two questions:
  1. The invisible axes don't scale like the other axes. The first is one with many lines plotted on it, while the second is a bar plot, drawn with the intention of creating a color code for an img plotted on the same space. the reason for this legend related callback is because for whatever reason, I can't make the axes scale identically. Is there some content I can load into the invisible axes that will solve this?
  2. In the event I can't get the two axes to scale identically, I need to make this callback work slighty differently. At the moment, making the function invisible leads to the callback being disabled for some reason - is there another callback which I may be able to take advantage of, which is triggered in the event of a resizing (or which I can enable to be so) which is not influenced by figure visibility.
Any help would be appreciated


Show 8 older comments
aboharbf on 7 Jul 2019
Hey Jan, Yair,
That sounds like a great strategy, but sadly since I'm using openfig, it doesn't seem like it accepts arguments pairs, which means I'd have to make it visible on screen, then move and resize vs. make it visible, resize, then invisible. After doing tic toc on both strategies, it seems like moving it alongside the resize is much quicker than the resize/invisible option, so I may stick with this. Thanks for the suggestion.
Jan on 8 Jul 2019
"it doesn't seem like it accepts arguments pairs" - Please post the code and show us, what let you assume, that arguments are not accepted. openfig() does not do any magic and you can inspect the code and modify a copy to satisfy your needs.
I do not understand the difference between: "make it visible on screen, then move and resize" and "make it visible, resize, then invisible". It is also not clear to me, why tic/toc matters here: If a code does not do, what you need, why does its speed play any rule? Did you include a drawnow insice the tic/toc?
aboharbf on 10 Jul 2019
Code below:
for ii = 1:length(figsToPlot)
figHand(ii) = openfig(figsToPlot{ii});
figHand(ii).Units = 'inches';
figHand(ii).Position = [24 24 pageLayout{ii}.*pageSize];
I'd rather avoid modifying openfig, insofar as If I download a new version of MATLAB on another machine, I'd rather this not break. Ultimately, the reason I wanted to open the figures invisibly was to save time when I'm running this on many figures.
What I meant by the sequence of explanations was the code above is faster than the code below.
for ii = 1:length(figsToPlot)
figHand(ii) = openfig(figsToPlot{ii});
figHand(ii).Units = 'inches';
figHand(ii).Position(3:4) = [pageLayout{ii}.*pageSize];
figHand(ii).Visible = 'off'
both fragments of code achieve something very similar, but the former is faster. I don't mind the figures being visible as long as it doesn't slow down anything, which seems to be the case when you place them off the screen.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!