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:
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])
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])
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'
.