Ask Your Question
1

Legend for histogram

asked 2017-01-07 05:21:19 -0500

Acksl gravatar image

updated 2017-01-08 09:37:43 -0500

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-01-07 13:54:23 -0500

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

h.set_legend_options(handlelength=1)
edit flag offensive delete link more

Comments

1
kcrisman gravatar imagekcrisman ( 2017-01-07 22:45:00 -0500 )edit

Perfect, thanks! :)

Acksl gravatar imageAcksl ( 2017-01-08 06:28:39 -0500 )edit

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

tmonteil gravatar imagetmonteil ( 2017-01-08 09:38:52 -0500 )edit

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 ( 2017-01-09 09:54:18 -0500 )edit

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: 2017-01-07 05:21:19 -0500

Seen: 89 times

Last updated: Jan 07