I have a figure with two or more lines. These lines have additional, important information associated with them, like how many data points were averaged to create the line etc. I would like to access this information in my figure.
I thought a good solution for this would be to if you could hover over a line with your mouse and get that extended information.
However searching for tooltips/overlays/hover-over on figures seemed to not be fruitful.
Example:
figure; hold on;
plot(1:10,rand(10,1))
plot(1:10,rand(10,1))
% additional info
plot_1_info.name = 'Alice';
plot_2_info.name = 'Bob';
plot_1_info.age = 24;
plot_2_info.age = 12;
Any good solutions or better approaches for this?
Using the new data tip customization system introduced in R2019a, we can do the following:
Which yields:
Notice that the "hover datatip" has black text, while the "click datatip" has blue text - this is default behavior.
You can change the data cursor behaviour, this option has good backwards compatability (I've tested the below in R2017b, used similar before in 15b).
See my comments for details:
Output:
Note: I've not handled anywhere the case that there is more than one data cursor tip. You can easily implement a loop over
idx
within the callback to handle this, I leave it as an exercise.This approach is really flexible. For instance if we had 3 lines (one per 'person') then they can each have their own
UserData
struct, and we don't need to repeat all the info in table rows.