
add text to subplot
6 views (last 30 days)
Show older comments
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 Comments
Adam Danz
on 24 Aug 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
on 24 Aug 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.
Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!