Search code examples
matlabhistogramlegendcaption

Caption/Label for vertical line in Matlab histogram


I use Matlab to plot some returns in a histogram. I would like to see the 0.005 quantile in the Plot via a vertical line This works with the following code

q = 0.995;
MSCIq = quantile(MSCIan, 1-q)

nbins = 50;
histMSCI = histogram(MSCIan, nbins)
xlabel('MSCI')
ylabel('count')
title('test')
line([MSCIq MSCIq], ylim, 'Color', 'r')

enter image description here

I would like to label the vertical line with a text and the value of MSCIq. (Say MSCIq= -0.44 then I would like to have something like "Value-at-Risk = -0.44"). Either directly at the line or in form of a legend. Does anyone know how to to this??


Solution

  • hold on;
    text(100, 300, 'MSCIq= -0.44');
    hold off;