0

I am trying to label my horizontal (constant y-axis) plot lines in MATLAB. However, some y-lines overlap and therefore their labels also overlap as shown:

'Min' and 'Max' lines overlap so their labels overlap

How may I separate these labels? I am simply using the yline function in MATLAB for the horizontal lines.

ymax = 0;
ymin = 0;
yline([ymax,ymin],'-',{'Max','Min'})
set(gca,'ylim',[-10,100])

1 Answer 1

1

One approach could be to set the LabelVerticalAlignment property for one of the two lines to 'bottom', as follows:

ymax = 0;
ymin = 0;
yline(ymax,'-','Max')
yline(ymin,'-','Min','LabelVerticalAlignment','bottom')
set(gca,'ylim',[-10,100])

enter image description here

This property can be set to 'top' (default), 'middle' or 'bottom'.

There is also a LabelHorizontalAlignment, which can be set to 'right' (default), 'left' or 'center'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.