How to enable plotted data to be highlight when mouse hover over but not diplay coordinate information when clicked
35 views (last 30 days)
Show older comments
Hi, I am trying to disable my scatter plot from showing coordinate information when clicked, but I would also like to keep the highlight on when i have the cursor hovering over the dots. I have so far tried using HitTest and DataCursorManager, or disabling the DataTipInteraction. But any of these operations would also disable the highlight feature. Any suggestions on resolving this issue?
0 Comments
Accepted Answer
Uday Pradhan
on 11 Sep 2020
Edited: Uday Pradhan
on 11 Sep 2020
Hi Yunhao,
It is my understanding that you would like to remove the coordinates information which is displayed when we click on any data point in the scatter plot.
This can be done by altering the default DataTipTemplate property of the “scatter” object once it has been plotted. As an example:
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
sca = scatter(x,y) %plot the scatter
dtt = sca.DataTipTemplate; %extract the default data tip template
dtt.DataTipRows(1).Value = ''; %the DataTipRows property stores the information to be displayed when user clicks,i.e. x – value and label
dtt.DataTipRows(1).Label = ''; %replace all these by empty values
dtt.DataTipRows(1).Value = ''; %same thing for the Y – values as well
dtt.DataTipRows(1).Label = '';
This will remove the coordinates information but keep the black dot as highlight when a data point is clicked.
You may notice that the same lines are executed twice. This is because, by default, "dtt.DataTipRows" is a 2 – by – 1 "DataTipTextRow" array containing information about the x and y coordinates of the clicked point. So, when we replace the default values for the x - coordinate with empty character, this array transforms to a 1 – by – 1 "DataTipTextRow array" and only the y – coordinate information is left. The last two lines of the code removes that information as well.
Hope this helps.
2 Comments
Uday Pradhan
on 11 Sep 2020
Please accept the answer if it resolved your issue. It helps other community members who have similar doubts.
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!