Show line above surf plot in 2D view
Show older comments
Hello,
I'm trying to modify ginput such that it will allow the following:
I have a 2D matrix. I plot the values in an axes using "surf" with a custom colormap. This part works.
Click a point on the graph. Move the mouse. Draw a line, connecting the first point click to the current position of the mouse.
The problem is, even with my efforts to draw the line in front, it shows up hidden behind my plot.
This is the code that executes in ginputmodded after the first click:
if isempty(out1)
lineconnect = line('LineWidth',5, ...
'XData',[pt(1,1),pt(1,1)], 'YData',[pt(1,2),pt(1,2)])
v = allchild(gca)
vsize = length(v);
lineposinv = find(v == lineconnect)%index of lineconnect in v
uistack(lineconnect,'up', lineposinv-1)%move lineconnect to front
v = allchild(gca)
linestore(lineconnect);
end
The following executes when the mouse is moved (WindowButtonMotionFcn):
function dummy()
pts = pointstore;
if ~isempty(pts) %block only executes after a point is clicked
lineconnect = linestore();
cp = get(gca,'CurrentPoint');
set(lineconnect,'XData',[pts(1,1),cp(1,1)],...
'YData',[pts(1,2),cp(1,2)]);
v = allchild(gca)
vsize = length(v);
lineposinv = find(v == lineconnect)%index of lineconnect in v
uistack(lineconnect,'up', lineposinv-1)%move to front
v = allchild(gca)
linestore(lineconnect);
end
end
linestore and pointstore are helper functions that store a persistent variable. They work fine.
Any ideas how I could make this work properly? I'm using MATLAB R2014a on Windows 7.
Accepted Answer
More Answers (1)
Ben11
on 6 Aug 2014
You could try to inverse the order of your axes' children after drawing the line, so that it comes up at the front and the plot stays at the back:
set(gca,'children',flipud(get(gca,'children')));
I can't test it now though so it might very well not work in your case :)
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!