Live line plotting over a surface/mesh/imagesc plot.
Show older comments
Hello,
I have a matrix (size 1000x1000) of height values, that I can view with mesh command. From the same figure (that mesh is displayed) I use ginput to the get the coordinates of the mouse and based on the coordinates I can plot the horizontal and vertical line profiles:
[x y] = ginput(1);
figure(2)
subplot(2, 1, 1)
set(gcf, 'Units', 'Inches', 'Position', [5, 5, 10, 3], 'PaperUnits', 'Inches', 'PaperSize', [16, 9.0])
plot(Zp(:, round(x(1))), 'b-'); title('Vertical'); grid on
subplot(2, 1, 2);
plot(Zp(round(y(1)), :), 'k-'); title('Horizontal');
Now, what I really need is a live line profile plotting, so as I drag the mouse over the mesh figure I can see the two line profiles.
It is like continuously updating the values of x(1) and y(1) and updating figure(2).
Is it even possible? And if so, could anyone guide me with how to do it?
Thanks.
11 Comments
Adam Danz
on 10 Mar 2020
What is "live line profile plotting" ?
"as I drag the mouse over the mesh figure I can see the two line profiles" - I'm lost.
Adam Danz
on 10 Mar 2020
What would the subplot(2,1,1) look like for any given pair of columns/rows ?
Feri
on 10 Mar 2020
Adam Danz
on 10 Mar 2020
I think you'll have to reconsider how the user will interact with the data to select which column and row will be plotted. The data you describe (1000x1000) has 1 million coordinates and the graphic updates won't keep up with a smoothly moving mouse.
Here's a demo the shows this problem. The data is 30x30 (see 1st line of code) and the mouseMove function only does two simple things 1) updates the title of the axis and 2) shows crosshairs. Copy it to a new m-file and run it.
As you can see, it runs fairly smoothly.
Now, change the first line to data = randi(100,1000,1000); to match your data size and run it again. You'll have to leave the mouse in place for quite a long time to allow the graphics to update to the new mouse position.
data = randi(100,30,30);
ax = gca() ;
mesh(ax, data)
view(ax, 2) % assumed
axis(ax,'tight') % required
xl = xline(min(xlim(ax)), 'k-');
yl = yline(min(ylim(ax)), 'k-');
set(gcf,'windowbuttonmotionfcn', {@mouseMove, data, xl, yl, ax});
function mouseMove(object, eventdata, data, xl, yl, ax)
% Get mouse coordinate
C = get(gca, 'CurrentPoint');
x = round(C(1,1));
y = round(C(1,2));
% If mouse isn't on axis, do nothing.
if x < ax.XLim(1) || x > ax.XLim(2) || y < ax.YLim(1) || y > ax.YLim(2)
return
end
% Update crosshairs
xl.Value = x;
yl.Value = y;
% plot((1:length(Zp)), Zp(round(y), :), '.');
title(gca, ['(X,Y) = (', num2str(x), ', ',num2str(y), ')']);
end
Feri
on 10 Mar 2020
I don't think that approach can be made faster. You can remove the "data" variable from the mouseMove inputs and the windowbuttonmotionfcn inputs (it's not being used) and you can even comment-out the two lines that update the crosshairs but the problem still persists.
Even replacing the windobuttonmotionfcn idea with ginput(1) takes a lot of time.
You could create a small GUI with two inputs where user enters a row number and a col num which updates two subplots. That's not as interactive as you'd like but it would probably be much faster.
"how can I plot the row and column pairs in another plot "
The x and y variables are the row and col numbers. You just need to use those to index the data variable.
From your question, "I have a matrix (size 1000x1000) of height values, that I can view with mesh command", is that really what you want to do? This creates a 3D plot (as in my answer).
Feri
on 11 Mar 2020
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
