Skip to content

Commit

Permalink
Optionally allow the legend label to be specified directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekfriis committed Mar 8, 2013
1 parent 4687e37 commit bbcb64a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rootpy/plotting/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ def Draw(self, *args, **kwargs):
self.pad.Modified()
self.pad.Update()

def AddEntry(self, thing, legendstyle=None):
def AddEntry(self, thing, legendstyle=None, label=None):

This comment has been minimized.

Copy link
@pwaller

pwaller Jun 6, 2013

Member

@ndawe @ekfriis Oh man. I realise this was done for backwards compatibility, but this swaps the argument order between root and rootpy. Now all my legends show my legend style as the text. Do you guys mind if we swap this around so that one could sanely transition from plain-root to rootpy legends?

This comment has been minimized.

Copy link
@ekfriis

ekfriis Jun 6, 2013

Author Member

I am wholeheartedly in favor of the swap.

This comment has been minimized.

Copy link
@pwaller

pwaller Jun 6, 2013

Member

PR #302.

"""
Add an entry to the legend.
If legendstyle is None, it will be taken from thing's
'legendstyle' attribute.
If label is None, the thing's title will be used as the label.
"""

if isinstance(thing, HistStack):
things = thing
Expand All @@ -60,8 +68,10 @@ def AddEntry(self, thing, legendstyle=None):
type(thing))
for hist in things:
if hist.inlegend:
if label is None:
label = hist.GetTitle()
if legendstyle is None:
legendstyle = hist.legendstyle
ROOT.TLegend.AddEntry(self, hist, hist.GetTitle(), legendstyle)
ROOT.TLegend.AddEntry(self, hist, label, legendstyle)
self.pad.Modified()
self.pad.Update()

0 comments on commit bbcb64a

Please sign in to comment.