Why does using 'ButtonDownFcn' function disable datatip?
조회 수: 19 (최근 30일)
이전 댓글 표시
I currently have a plot that has a custom data tip. My goal is to be able to have the user click on a point on the plot (which displays the datatip) and be able to store the coordinate of the datatip as well as create another plot. I went about this by creating a ButtonDownFcn function to store the coordinate and then create another figure; however, when this happens my custom datatip doesn't show up anymore.
So for clarity I need to be able to read when the user clicks on a point and then:
- display a custom datatip
- store the coordinates of the datatip
- then create another plot
This is my code:
%Plots data
tbl = readtable("FINAL_898_AbdVagAntGast_FASCCILE1.xlsx");
s = scatter(tbl,'Var3','Var4','filled');
%%Creates custom datatip
datatip(s,'Visible','off');
s.DataTipTemplate.DataTipRows(1).Label = "X";
s.DataTipTemplate.DataTipRows(2).Label = "Y";
row = dataTipTextRow("Diameter",tbl.Var11);
row2 = dataTipTextRow("Myelin Thickness",tbl.Var13);
s.DataTipTemplate.DataTipRows(end+1) = row;
s.DataTipTemplate.DataTipRows(end+1) = row2;
%%Stores coordinate and creates second plot
set(s, 'ButtonDownFcn', @mousecon);
function mousecon(~,~)
p = get(gca,'CurrentPoint');
x = p(1);
y = p(2);
figure
tbl = readtable("Rawdata_898_AbdVagAntGast_FASCICLE1_UnmyelinatedAxons_2.xlsx");
scatter(tbl,"X","Y",'filled')
end
댓글 수: 0
답변 (1개)
Adam Danz
2022년 8월 7일
편집: Adam Danz
2022년 8월 8일
> Why does using 'ButtonDownFcn' function disable datatip?
When you click on an object, the object has no idea of your intentions. All it knows is that there was a click. Suppose you have a ButtonDownFcn that is designed to delete the object. How should the object decide whether to delete itself after a click or assign a data tip to the location of the click? Thus, when a ButtonDownFcn is assigned, datatips are disabled.
You can, however, set the UpdateFcn of datacursormode. The function will execute every time a datatip is added. See this answer for more info and examples.
> My goal is to be able to have the user click on a point on the plot (which displays the datatip) and be able to store the coordinate of the datatip as well as create another plot.
This answer reviews 5 methods to access data tip content.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!