- https://www.mathworks.com/help/matlab/ref/annotation.html
- https://www.mathworks.com/help/matlab/ref/matlab.graphics.shape.internal.datacursormanager.html
- https://www.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html
How to set PointDataTip properties and set DataTipStyle
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to make an interactive plot to select portions of a line graph. I want to use the datatip functionality to display X and Y coordinates, but not on the point in the graph. Instead I want this to be in the bottom right hand corner or any other position thast does not overlap with the lineplot.
I noticed that moving the cursor over any plot can procuce a number of datatip windows that won't go away. I Found the remedy by using
delete(findall(fh,'Type','hggroup'));
Now I want to move the position of the datatip to a unused corner of the graph (and not get a multityde of datatips whenever I click on the graph).
I tried
dcm=datacursormode(figurehandle);
set( dcm, 'DisplayStyle', 'window')
This does not make a difference in the datatip window appearance of behaviour.
I tried
dth = findall( figurehandle,'Type','hggroup'); get( dth )
and found a promising attribute DataTipStyle: MarkerAndTip
I then searched the Help window and the website for possible v alues of this property and what it does and I found nothing! I used to be able to right click on a datatip and chnage the display style to 'window'. This would be what I want, but I woul like to set it explicitly in the script to create the interactive graph.
How can I do this? (I am stil runnoing R2019a because the installation of R2020 was a disaster giving me errors on all graphics and help just stopped).
0 comentarios
Respuestas (1)
Suraj Kumar
el 24 de Mayo de 2024
Hi Ronald,
To display the information of the selected points in a line graph at the bottom right corner and avoid the cluttering of data tips, you can follow the steps below:
1. Define a custom update function for the data cursor mode instead of using the default data tip pop-ups. This function handles the display of coordinates in a controlled manner, ensuring that previous data tips do not accumulate.
2. To display the X and Y coordinates in a specific location without overlapping the plot, you can create a textbox annotation on the figure. This annotation displays the coordinates and is placed in the desired location, avoiding any overlap with the line plot.
You can refer the below mentioned code and the output for better understanding:
dcm = datacursormode(figureHandle);
set(dcm, 'Enable', 'on');
% Set custom update function for datatips
set(dcm, 'UpdateFcn', @myUpdateFcn);
function txt = myUpdateFcn(~, event_obj)
pos = get(event_obj, 'Position');
x = pos(1);
y = pos(2);
txt = {['X: ', num2str(x)], ['Y: ', num2str(y)]};
% Delete existing annotations to prevent overlap
delete(findall(gcf, 'Tag', 'DataTipAnnotation'));
% Create a new annotation
annotation('textbox', [0.7, 0.1, 0.2, 0.1], 'String', txt, 'Tag', 'DataTipAnnotation', 'FitBoxToText', 'on', 'BackgroundColor', 'white');
% Return empty to prevent the default datatip from showing
txt = '';
end
Output:
For more insights on annotations, the data cursor manager and function handles in MATLAB, you can go through the following documentations:
Hope this helps!
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!