putting a text in a white space on a plot

11 views (last 30 days)
I have some plots that I want to write a text on them but I want to place the text in a white space inside plot. I wonder how I can do that?
x=rand(10,10);
y=rand(10,10);
plot(x,y,'o'); % I want to show the following text in a white space inside the plot window
text('L=C0*D+C1');

Accepted Answer

Paulo Silva
Paulo Silva on 12 Jun 2011
What you are asking for isn't easy to implement but can be done, what the code has to do is the search for one empty space big enough for that text, there's also a chance that there's no such space available and the code will fail.
There are alternatives like using the legend, xlabel, ylabel and title. Also title can have many lines
title({'Main Title text'; 'Subtitle text'});
or this solution:
title(['\fontsize{14} Main Title ', ...
'\newline \fontsize{10} \color{red} \it My Subtitle']);
There is also the gtext function that allows the user to select where to put the text.
  3 Comments
Paulo Silva
Paulo Silva on 12 Jun 2011
My name is Paulo not Paula, what you want to do is waste time and add more code to your program just to do that simple thing, ok buy you already know the basic idea "what I meant was finding a space with less density of data (or maximum white space) and putting the text in center of it" so start coding that and see if it's really needed.
Hassan
Hassan on 12 Jun 2011
Sorry Paulo for misspelling your name. Well, I just wondered someone may have it done it before since especially for me who is not good in programming it will take ages.

Sign in to comment.

More Answers (1)

Jan
Jan on 12 Jun 2011
Look in the code of LEGEND, subfunction lscan. This function has 92 lines, because the task is not trivial. But when the found location is nice for a legend, a text may be matching also.
  1 Comment
Hassan
Hassan on 12 Jun 2011
I will do and hope to find an answer there, thanks Jan for the help.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!