Optimize location of a TLegend

I am wondering if anybody knows how to optimize location of a given TLegend. I came to this point because sometimes I have lots of histograms, and if I fixed the location of my legend, then sometimes it will cover histogram of interest. In the mean time, I don’t think it is a good idea to adjust its location case by case. So I am trying to find a method which can optimize the location to avoid the covering on interesting part.


Nothing is impossible, but your request would not be trivial to implement.
This requires doing pattern recognition in the picture looking for areas with no graphics. In fact it cannot be done at the time the TLegend object is drawn because you can always draw other objects after the TLegend.