Ask Your Question
1

Legend for histogram

asked 2017-01-07 12:21:19 +0100

Acksl gravatar image

updated 2023-01-09 23:59:41 +0100

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 20:54:23 +0100

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-08 05:45:00 +0100 )edit

Perfect, thanks! :)

Acksl gravatar imageAcksl ( 2017-01-08 13:28:39 +0100 )edit

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

tmonteil gravatar imagetmonteil ( 2017-01-08 16:38:52 +0100 )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 16:54:18 +0100 )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 12:21:19 +0100

Seen: 487 times

Last updated: Jan 07 '17