MATLAB Answers

Legend title only without marker and lines of data

253 views (last 30 days)
Maniraj M
Maniraj M on 21 Apr 2018
Commented: Maniraj M on 22 Apr 2018
Hi all, Are there any way to get rid of data related marks and only display title of the legend. Any suggestion would be great.

  4 Comments

Show 1 older comment
Maniraj M
Maniraj M on 21 Apr 2018
You are perfectly correct. But, text needs position values which dependent on axis value, in my case. Somehow legend appears at correct location perfectly where I wanted. So,looking for some work around.
David Fletcher
David Fletcher on 21 Apr 2018
You could get the handle to the legend; get its position property; then set the position of the text to be the same position as the legend. Or if you want the text to just be somewhere upper right of the graph, set the Units property of the text object to 'normalized' and somewhere around 0.9,0.9 would be around the upper right corner.
Maniraj M
Maniraj M on 21 Apr 2018
Well, thanks for your suggestion. But, I have tried already this idea and is not fulfilling the requirements for handling large number of figures. I could not use figure frame as input for text, when one has some plot. I am mainly looking for simplest option to keep text at right-side top (irrespective of range of scale values used for plots). Some time it feels that matlab is oversimplified.

Sign in to comment.

Accepted Answer

David Fletcher
David Fletcher on 21 Apr 2018

Looks like the text position is consistently in the upper right (irrespective of range scale values) to me, but if you say you've tried it and it's not fulfilling your requirements then fair enough. I can't say I have any other ideas.

for iter=1:30
    dataX=randi(randi(100,1,1),1,randi(30,1,1))
    dataY=randi(randi(100,1,1),1,length(dataX))
    figure(iter)
    plot(dataX,dataY)
    text(0.9,0.9,'tst','Units','normalized')
end

  1 Comment

Maniraj M
Maniraj M on 22 Apr 2018
Thanks a lot. The 'Units','normalized' was missing in my code. I miss understood that if I normalized the figure window, it will be for all. my bad. This part keeps the text at correct position.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 21 Apr 2018
dummyh = line(nan, nan, 'Linestyle', 'none', 'Marker', 'none', 'Color', 'none');
legend(dummyh, 'One legend entry to rule them all!')

This will leave empty space for the line, but there will still be a gap there.

  1 Comment

Sign in to comment.

Sign in to answer this question.

Tags