Invisible graphics objects are selectable

I have a plot with a legend so large it covers up some of the data. I thought it would be a good idea to add a keyboard function to hide the legend, so the user can temporarily hide the legend and interrogate the data (e.g. using the Data Cursor).
However, setting the legend "Visible" property to "off" still allows it to be selected. You can't click on plot lines because the invisible legend is covering them up.
Example:
figure();
plot(1:20,1:20);
L=legend({'blah'});
L.Position = [.05 .05 .9 .9];
L.Visible='off';
%Now try using the Data Cursor to select some data
Surely this can't be the intended behavior? I looked through the documentation for legend properties but could not find any anything that suggested this behavior could be changed.
I have some ideas for a work-around for the current application (When setting Visible='off', copy the Position property to UserData and set the Position to [-1 -1 0 0]. When setting Visible='on', set Position back to the original value).
However, this seems pretty basic so I don't want to waste time on a work-around. Am I missing something?

 채택된 답변

Stephen23
Stephen23 2018년 9월 29일
편집: Stephen23 2018년 9월 29일

0 개 추천

You could use uistack to move the legend behind everything else, and then move it back to the front afterward. I have not tried this, but it might work.

댓글 수: 6

jg
jg 2018년 9월 29일
I already tried that. Uistack doesn't appear to work on legends (or at least it won't put it behind the axes).
Stephen23
Stephen23 2018년 9월 29일
편집: Stephen23 2018년 9월 29일
Okay, lets try some other plans.
B) change the 'PickableParts' property to 'none':
C) move the legend to a position somewhere outside of your visible screen.
This method is used sometimes for plotting without getting in they way. It would be really nice if there was a location option 'offscreen', but you will have to do this yourself. You might be able to open some graphics function, e.g. movegui, and see how they detect the screen position.
jg
jg 2018년 10월 1일
That is essentially the work-around I already proposed. I am able to set the position to -1,-1 which puts it off the figure.
Stephen23
Stephen23 2018년 10월 1일
편집: Stephen23 2018년 10월 1일
@jg: did you try setting the PickableParts property?
jg
jg 2018년 10월 2일
Sorry, I hadn't because I thought you suggested doing both that and moving the legend. Setting PickableParts='none' works.
I don't understand why PickableParts='visible' lets you select a legend when Visible='off'. That doesn't seem to be consistent with the documentation I read. I guess that's a question for Mathworks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

jg
2018년 9월 28일

댓글:

2018년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by