add text to subplot

조회 수: 8 (최근 30일)
Djdj Cjcjxj
Djdj Cjcjxj 2020년 8월 24일
댓글: dpb 2020년 8월 24일
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
Adam Danz
Adam Danz 2020년 8월 24일
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 2020년 8월 24일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by