Bug when using data cursor with subplots having (some) equal X and Y values
1 次查看(过去 30 天)
显示 更早的评论
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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157836/image.png)
Figure 2 (bug, occuring when I click on the same position but in a different subplot)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157837/image.png)
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')
0 个评论
回答(2 个)
Vidya Viswanathan
2016-4-1
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
0 个评论
Jasper van Casteren
2018-11-22
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!