How can one put mean and std of the data into histogram using annotation?
Show older comments
discusss how to put mean and std information in legend of histogram. But I would like to put these information in annotation
Please advise.
5 Comments
Walter Roberson
on 13 Aug 2020
Would you be looking for a plain text annotation? If so then is there a reason to use annotation() instead of text() ?
If you are looking for something like text with an arrow, where would you like the text to be and where would you like it to point to?
alpedhuez
on 14 Aug 2020
Walter Roberson
on 15 Aug 2020
legend() has a Position property.
I do not understand yet why you want to use annotation() instead of text()? text() would permit you to use data coordinates, but annotation() requires figure coordinates.
Steven Lord
on 15 Aug 2020
Can you show a picture of what you want the histogram with annotation to look like? That may help us suggest the best options.
Personally I might just go with xline objects.
x = randn(1, 1e5);
histogram(x)
xline(mean(x), 'LineStyle', '--', 'Color', 'r', 'LineWidth', 2)
xline(std(x), 'LineStyle', ':', 'Color', 'c', 'LineWidth', 1.5)
xline(-std(x), 'LineStyle', ':', 'Color', 'c', 'LineWidth', 1.5)
Accepted Answer
More Answers (1)
Sulaymon Eshkabilov
on 15 Aug 2020
Hi,
A user can fully control the location of the legend by indicating its location as:
legend({sprintf('mean = %3.2f, std = %3.2f', mean(D), std(D))}, 'location', 'best') % Puts the legend automatically on an empty spot
legend({sprintf('mean = %3.2f, std = %3.2f', mean(D), std(D))}, 'location', 'southwest') % Puts on the lower left corner
legend({sprintf('mean = %3.2f, std = %3.2f', mean(D), std(D))}, 'location', 'southeast') % Puts on the lower right corner
legend({sprintf('mean = %3.2f, std = %3.2f', mean(D), std(D))}, 'location', 'northwest') % Puts on the upper left
legend({sprintf('mean = %3.2f, std = %3.2f', mean(D), std(D))}, 'location', 'southeast') % Puts on the upper right
1 Comment
Categories
Find more on Display 2-D Images 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!