Sundar R
Sundar R

Reputation: 14705

Figuring out where to add text in a MATLAB histogram

I have a MATLAB histogram graph produced with some data, with some 50 bins. I now need to insert a line of text into the graph, at any place where it wouldn't tangle with the histogram bars. The text is basically 'Period of data used: mmm dd to mmm dd' (I mention this to give an idea of the width required and where the text can be split if necessary).

One method I considered was finding out a series of contiguous histogram bins where the freq (y axis) remains less than 90% of the maximum of all frequencies; then, the text can be printed at the x position starting at the first of those bins near the top of the graph.

Is this a good way of going about it? If so, how do I compute this contiguous series of bins without looping around?

Or is there a better way of placing this text adaptively according to the data?

Edit: Due to other considerations, the number of histogram bins is not a fixed 50 any more, but rather xmax/20 where xmax is the maximum x-axis value. Algorithms that depend on working on aggregates of a number of bins might need to take this variability into account, when calculating that number.

Upvotes: 0

Views: 1484

Answers (1)

nkjt
nkjt

Reputation: 7817

I think the simplest way would be to use a multiline title, optionally along with TeX formatting to de-emphasise the additional info. To make a multiline title, pass a cell array of strings like this:

title({'\fontsize{16}Actual Title';'\fontsize{8}other info'})

Being consistent across the histograms, I think this would look tidier than having text on the graph itself that might move around.

Upvotes: 1

Related Questions