How to :Data cursor displaying colorbar value?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dean Kueh
le 6 Mai 2017
Commenté : Walter Roberson
le 8 Mai 2017
Hi guys,
Currently I have a 2D scatter plot with 3 column vectors. They are Pj, ecc and Combo.bresult .The third column is represented by a color bar.
I am lost as to how to display the third column value(the color bar value) when using data cursor mode. Currrently it only shows the x and y coordinate.
Thanks !
0 commentaires
Réponse acceptée
Walter Roberson
le 6 Mai 2017
dcm_obj = datacursormode();
set(dcm_obj,'UpdateFcn',@(hObject, event_obj) myupdatefcn(hObject, event_obj, Pj, ecc, Combo.bresult) );
function output_txt = myfunction(~, event_obj, Pj, ecc, bresult)
% ~ Currently not used (empty)
% event_obj Object containing event data structure
% output_txt Data cursor text
%find the closest data point to the cursor
cursor_pos = event_obj.Position;
dist2_to_dots = (Pj - cursor_pos(1)).^2 + (ecc - cursor_pos(2)).^2;
[~, item_idx] = min(dist2_to_dots);
output_txt = {sprintf('Pj: %g', Pj(item_idx)), sprintf('ecc: %g', ecc(item_idx)), sprintf('br: %g', bresult(item_idx)) };
10 commentaires
Walter Roberson
le 8 Mai 2017
You can pass the text formats to use into mypdatefcn to generalize it
set(dcm_obj, 'UpdateFcn', @(hObject, event_obj) myupdatefcn(hObject, event_obj, X, Y, Z, {'ecc: %g', '1/Pj: %g', 'br: %g'}) );
and
function output_txt = myupdatefcn(~, event_obj, X, Y, Z, formats)
% ~ Currently not used (empty)
% event_obj Object containing event data structure
% output_txt Data cursor text
%find the closest data point to the cursor
cursor_pos = event_obj.Position;
dist2_to_dots = (X - cursor_pos(1)).^2 + (Y - cursor_pos(2)).^2;
[~, item_idx] = min(dist2_to_dots);
output_txt = {sprintf(formats{1}, X(item_idx)), formats{2}, Y(item_idx)), sprintf(formats{3}, Z(item_idx)) };
However, note that you can only have one active dcm object per figure, so if you want to be able to point to different lines and have different text labels come up depending on what was being pointed to, then you need to code a single update function that handles everything simultaneously.
One approach to handle multiple plots simultaneously would be to set the UserData property of each drawn object to have the associated extra data and the text formats to use; then the data cursor update function would have to figure out which object it was near, and retrieve the appropriate information to update the display. See related https://www.mathworks.com/matlabcentral/answers/219797-check-if-mouse-is-above-an-axes#answer_180771
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Properties dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!