Function like text() but with auto placement like legend?
Mostra commenti meno recenti
Does such a function exist which simply addes some text to a plot, without having specify the x/y location, and without also adding a line/marker graphic?
In other words, I am looking for a function which has output like text() (i.e., no other graphics, like legend() has), but which has the ability to intelligently place the text object, as in legend(), i.e.
legend(____,'Location',_____)
7 Commenti
Stephen23
il 3 Mag 2017
"Does such a function exist which simply addes some text to a plot, without also adding a line/marker graphic?"
text()
Evan
il 3 Mag 2017
Jan
il 3 Mag 2017
Of course text() requires a position. Where shoudl it be placed without a location? In the upper left or in the center or outside the diagram? Matlab cannot guess this detail.
"Without adding a line/marker graphic"? text() does not do this, so why do you ask for this detail?
Please explain what you want to achieve. Omitting an required detail is not enough to specify, which behavior you want to get.
Evan
il 3 Mag 2017
Jan
il 3 Mag 2017
"Intelligently" sounds fine, but what is this? Where is an "intelligent" location for a text? I cannot imagine a situation where I want text to appear at a location I do not explicitely define.
Do you want to create a text at a location, which is not covered by a graphics object? Ah, this would be another story.
dpb
il 3 Mag 2017
OTOH, as noted in the Answer below, I can think of a multitude of instances wherein I would like text to be located "without being touched by human hands". :)
That's certainly one "intelligent", locating paradigm, yes...as noted, the one example I can think of presently in Matlab is legend with the 'best' location property value. It isn't always perfect, but is, on the whole in my experience, better than a random choice of a fixed location when one isn't positive a priori what the shape of the plotted data is.
Risposta accettata
Più risposte (4)
Walter Roberson
il 3 Mag 2017
In the case where you need only a single such item per axes:
h = line(nan, nan, 'Color', 'none');
legend(h, 'Your Message Here', 'Location', ....)
4 Commenti
Evan
il 3 Mag 2017
dpb
il 4 Mag 2017
Yeah, the NaN data in plotting often solves "issues"; didn't think of it in this particular context as was fixated on the idea of labeling lines in the area of the data but missing it...
Pedro Busc
il 26 Mag 2020
How to remove the space used to the plotted item symbol (in this case none, blank) on the left?
Walter Roberson
il 26 Mag 2020
You would have to use two or more outputs for legend(), and access the graphic objects such as the text() object and adjust its Position property.
Note that two or more outputs for legend() is now undocumented and unsupported, and could be removed Any Release Now.
Evan
il 4 Mag 2017
Walter Roberson
il 9 Mag 2017
0 voti
2 Commenti
dpb
il 9 Mag 2017
I suppose the somebody who wrote this one thought it better than whatever was original...
IT Department
il 3 Gen 2020
Modificato: KSSV
il 11 Mar 2025
0 voti
There is a function in the Matlab File Exchange that addresses this issue.
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!