I have a Matlab GUI with 3 axes components. Their tags are predicted_ax
, cost_ax
and error_ax
. I want to draw vertical line on particular position on the first axes component (the one with tag predicted_ax
). How do I do that?
I tried this code:
ylim = get(handles.predicted_ax, 'ylim');
line([linePos, linePos], ylim);
But it draws the line on different axes (the ones with tag error_ax
)! I'm sure I did not confuse tags or axes components. In the fact another test
ylim = get(handles.cost_ax, 'ylim');
line([linePos, linePos], ylim);
gives exactly the same result: the line is drawn on the last axes component with tag error_ax
. So how do I draw the line on the right axes?
You need to set the 'parent' property of the line, as by default it will always be the current axis:
h = line([linePos, linePos], ylim);
set(h, 'parent', handles.predicted_ax);