In recent Matlab versions (I am using R2024b), when you hover or click on a line plotted on some axes it produces a data tip, which is a rectangle indicating the numerical values at that point.
I would like to disable data tips on all axes by default. For existing axes, it is enough to call the function disableDefaultInteractivity with those axes as input. But then, this would have to be done for every new axes. Is there a way to cause all axes to have data tips disabled by default?
I thought there would be some default property value in groot for this, but I can't find it. This answer suggests using the axes' CreateFcn property to call disableDefaultInteractivity, but that approach does not seem to work, at least not in all Matlab versions (see comments to that answer; it definitely does not work in R2024b).
I found a method that works for me in R2024b:
set(groot , 'defaultAxesCreateFcn' , 'set(gca, ''Interactions'', [])')
The code sets a groot property such that, by default, all created axes have 'set(gca, ''Interactions'', [])' as their CreateFcn. This means that, immediately after the axes have been created, their 'Interactions' property is set to []. This gets rid of the data tip interaction, as well as other interactions (which I currently don't care about).
Including this code in the startup.m file ensures that it is run when Matlab starts.
The documentation pages that helped me come up with this are:
Judging from the information on those pages, this approach may not work for some Matlab versions. I tested that it works in R2024b and in R2025b.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With