Rasto
Rasto

Reputation: 17794

How to draw vertical line on axes in Matlab GUI?

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?

Upvotes: 2

Views: 3327

Answers (2)

Isaac
Isaac

Reputation: 3616

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);

Upvotes: 3

Turix
Turix

Reputation: 4490

I think you need to use the axes command to set the current axis on which the line will be drawn. Try axes(handles.predicted_ax); prior to your line command.

(Getting the ylim value for the axis apparently does not make it current.)

Upvotes: 1

Related Questions