Effacer les filtres
Effacer les filtres

placing text outside the axis in the figure

78 vues (au cours des 30 derniers jours)
sermet
sermet le 19 Fév 2016
figure(1); hold on
scatter(1, 1, 100, 'k', 'o')
scatter(1, 2, 100, 'k', '+')
h = legend('circle', 'Plus', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
text=('information:')
I need to place text string outside the axis in the figure. If it is not possible I need to insert text right below the legend. Scatter data is not constant all the time so the location of the text wouldn't depend on the axis data.
Thanks in advance
  1 commentaire
Ingrid
Ingrid le 19 Fév 2016
why not just use the title command to show this information?

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 19 Fév 2016
I don’t know where you want to put them outside the axes, so this code puts them below the legend instead. It is adaptive, and uses the 'Position' property of the legend and the axis limits to place the text object. You will have to experiment with it to get the result you want:
figure(1); hold on
scatter(1, 1, 100, 'k', 'o')
scatter(1, 2, 100, 'k', '+')
h = legend('circle', 'Plus', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
axlim = get(gca, 'XLim'); % Get ‘XLim’ Vector
aylim = get(gca, 'YLim'); % Get ‘YLim’ Vector
legpos = get(h, 'Position'); % Get ‘legend’ 'Position' Vector
x_txt = min(axlim) + diff(axlim)*legpos(1) + 0.05*diff(aylim); % Set ‘x’-Coordinate Of Text Object
y_txt = min(aylim) + diff(aylim)*legpos(2) - 0.01*diff(aylim); % Set ‘y’-Coordinate Of Text Object
text(x_txt, y_txt, 'information:')

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by