Bug when using data cursor with subplots having (some) equal X and Y values

8 Ansichten (letzte 30 Tage)
Im using R2014b. When i have a figure with multiple subplots and I use the data cursor I get the following bug: If I click on a point in any of the subplots, lets say at X=1,Y=1, a tooltip will appear and a marker (square) will be placed on that point, which is how it is supposed to work. However, when I click on the same position on a different subplot, the tooltip will stay at the same position, the old marker will become transparent and a new marker will be placed in the new subplot. Afaik this is a bug. To be clear, this only happens if I click on the same exact position in a different subplot (assuming a data point exists there). Figure 1 (correct behavior):
Figure 2 (bug, occuring when I click on the same position but in a different subplot)
Is there any solution or workaround for this? I tried checking the properties of the tooltip but I couldnt figure anything out. I found out that if I use copyobj to make a new tooltip (copy of the old one) it will actually display correctly.
Code to make the figures:
figure;subplot(2,1,1);
plot([1 1 1],'x')
subplot(2,1,2);
plot([0 1 2],'rx')

Antworten (2)

Vidya Viswanathan
Vidya Viswanathan am 1 Apr. 2016
Hi Paul,
Thank you for reporting this issue to us. I was able to reproduce this behavior at my end. I will forward this information to the developers and they might consider fixing it in one of the future releases. Meanwhile, if I come up with a workaround, I will post it here.
Regards,
Vidya

Jasper van Casteren
Jasper van Casteren am 22 Nov. 2018
This is caused by the fact that the datacursor is actually bound to the figure, not the axes.
I use
fig = figure;
ax1 = subplot(whatever);
ax2 = subplot(whatever);
datacursor = datacursormode(fig);
datacursor.set('UpdateFcn',@MyFunc);
% MyFunc must be an embedded function to know ax1 and ax2
function MyFunc(Target, evtObj)
if Target.Parent==ax1
whatever;
else
whatever;
end
end
To get the corretc datacursor text for each subplot.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by