Hovering mouse over multiple plots

조회 수: 18 (최근 30일)
Dharmesh Joshi
Dharmesh Joshi 2022년 5월 17일
댓글: Dharmesh Joshi 2023년 9월 22일
Hi All
I have multiple subplots, all with the same time stamp.
Is it possible that when i hover over one plot, i can also see the values from another plot at the same time as if i the mouse over that plot as well?
This how my plot looks:

답변 (1개)

VINAYAK LUHA
VINAYAK LUHA 2023년 9월 22일
편집: VINAYAK LUHA 2023년 9월 22일
Hi Dharmesh,
It is my understanding that you have multiple subplots plotted at same timestamps in a figure. While hovering over line points in a subplot, you want to know a workaround to see the corresponding y value in another subplot at the same x values.
Here’s a possible workaround for your reference using callbacks function which gets triggered on hovering over line points and leverages MATLAB Graphics object’s hierarchical relationships to find and display y values as tooltips in the subplot from another configured subplot.
close all
time = 7:16;
data1= randi([1,50],1,10)
data2= randi([51,100],1,10)
figure;
subplot(2, 1, 1);
plot(time, data1);
title('Plot 1');
subplot(2, 1, 2);
plot(time, data2);
title('Plot 2');
dcm_obj = datacursormode(gcf);
set(dcm_obj, 'UpdateFcn',@callbackfcn);
function output_txt = callbackfcn(~, event_obj)
pos = event_obj.Position;
x = pos(1);
% fetch y values from other subplot using child-parent relationship
y1 = interp1(event_obj.Target.XData, event_obj.Target.YData, x);
y2 = interp1(event_obj.Target.Parent.Parent.Children(1).Children.XData, event_obj.Target.Parent.Parent.Children(1).Children.YData, x);
% display data as tooltip
output_txt = {['X: ', num2str(x)], ['Y1: ', num2str(y1)], ['Y2: ', num2str(y2)]};
end
Result
Explore the following documentations for more details:
Regards
Vinayak Luha
  댓글 수: 1
Dharmesh Joshi
Dharmesh Joshi 2023년 9월 22일
Hi Vinayak
Yes to a degree, but the data should not be displayed on the plot i am hover over, but on the original plot where the data is displayed. In simple terms i am trying to hover my mouse over multple plots at the same time, but in actual fact the mouse would be over only on of the plots.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axes Appearance에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by