add text to subplot

I have a figure with 5 subplots. In each subplot there are various patches which I included using an array of x-values. Is it possible to add a textbox next to/below each patch?
I tried the following, but nothing came up:
ax(1)=subplot(5,1,1)
% code to create subplots
% x_left_value and x_right_value are two arrays with the respective x values
center_value = (x_left_value + x_right_value)/2;
side_value = (center_value - x_left_value)*[-1 1]
x_value = center_value + side_value;
y_value = ylim(ax(1))
patch1 = patch(ax(1), x_value([1 1 2 2]), y_value([1 2 2 1]), 'b','EdgeColor','r','FaceAlpha',0.1)
text(ax(1), x_left_value, x_right_value,'text here');
following is what I want to achieve:
any help thank you!

6 comentarios

dpb
dpb el 24 de Ag. de 2020
figure, subplot(5,1,1)
patch([1 2 2 1],[0 0 1 1],'r')
xlim([0 20])
htxt=text(1.5,-0.2,'Text','HorizontalAlignment','center');
htxt.FontSize=8;
results in
Djdj Cjcjxj
Djdj Cjcjxj el 24 de Ag. de 2020
where did you get 1.5 and -0.2 for the text x y values?
dpb
dpb el 24 de Ag. de 2020
x is center of patch X=[1 2 2 1];
>> mean([1 2 2 1])
ans =
1.5000
>>
y is arbitrary position below the y origin to place text outside the axis; "salt to suit".
Djdj Cjcjxj
Djdj Cjcjxj el 24 de Ag. de 2020
sorry, but it does not work
Adam Danz
Adam Danz el 24 de Ag. de 2020
What are the values of x_left_value, x_right_value?
By default, text objects have the "clipping" property set to 'off' which means they will appear even if the text extends beyond the axis limits. But if the text extends so far that it goes off the figure, you won't see it. If the text is under an opaque object, you also won't see it.
So, check that your text coordinates are reasonable.
dpb
dpb el 24 de Ag. de 2020
Of course it works...you see the figure. As Adam points out, if you don't use reasonable coordinate values or have the focus on the wrong axis or such, you may not have the desired result.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Ag. de 2020

Comentada:

dpb
el 24 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by