MATLAB Answers

0

How to add a specific value with arrow or a marker in the axis of a plot?

Asked by Ritabrata Chakraborty on 13 Mar 2019 at 14:29
Latest activity Commented on by Ritabrata Chakraborty on 17 Mar 2019 at 15:43
Accepted Answer by Jan
I have a 2D plot. I plotted a curve and the average of the data in the same plot. I want to write the average value beside the Y-axis to indicate the average value. How to write it ?

  4 Comments

Show 1 older comment
Thank You. It worked. I was trying to use figure editor and having trouble to pin point the location. Now it is accurate.
@Ritabrata Chakraborty: Is this a comment to my answer? Does my answer solve the problem?
@Jan Yes.. Using 'text' solve my problem. I inserted a value beside axis with 'text', then it was easily adjustable using plot edit options.

Sign in to comment.

Tags

Products


Release

R2018a

1 Answer

Answer by Jan
on 13 Mar 2019 at 14:49
 Accepted Answer

x = rand(1, 10);
m = mean(x);
axes('XLim', [1, 10], 'NextPlot', 'add', 'Box', 'on');
plot(x, 'b');
yline(m, 'g');
text(10.01, m, 'Mean', ...
'Color', 'g', ...
'HorizontalAlignment', 'left', ...
'Units', 'data');
The creates the text slightly right from the axes.

  1 Comment

@Jan I think using 'text' to insert the required word, and then edit the positioning and color with edit figure option is easier and faster option.

Sign in to comment.