Ask Your Question
1

Legend for histogram

asked 8 years ago

Acksl gravatar image

updated 2 years ago

tmonteil gravatar image

I can't make the legend for histograms work as I want it to. I can make a legend with the labels appear but the corresponding indicator doesn't show the colors just two black vertical lines.

Here's a minimial example:

d1=[randint(0,10) for i in range(20)]
d2=[randint(0,10) for i in range(20)]
h=histogram([d1,d2],label=["d1","d2"])
h.legend(True)
h

Any ideas?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 8 years ago

The colors are there but hidden by the indicator borders. Increase their size with

h.set_legend_options(handlelength=1)
Preview: (hide)
link

Comments

1
kcrisman gravatar imagekcrisman ( 8 years ago )

Perfect, thanks! :)

Acksl gravatar imageAcksl ( 8 years ago )

Great. Should a nonzero value set by default ? Or does this has effect somewhere else ?

tmonteil gravatar imagetmonteil ( 8 years ago )

Probably; http://matplotlib.org/api/legend_api.... says, "The pad and spacing parameters are measured in font-size units. e.g., a fontsize of 10 points and a handlelength=5 implies a handlelength of 50 points."

kcrisman gravatar imagekcrisman ( 8 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 8 years ago

Seen: 522 times

Last updated: Jan 07 '17