ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 09 Jan 2017 16:54:18 +0100Legend for histogramhttps://ask.sagemath.org/question/36210/legend-for-histogram/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?Sat, 07 Jan 2017 12:21:19 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/Answer by paulmasson for <p>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.</p>
<p>Here's a minimial example:</p>
<pre><code>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
</code></pre>
<p>Any ideas?</p>
https://ask.sagemath.org/question/36210/legend-for-histogram/?answer=36219#post-id-36219The colors are there but hidden by the indicator borders. Increase their size with
h.set_legend_options(handlelength=1)Sat, 07 Jan 2017 20:54:23 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/?answer=36219#post-id-36219Comment by kcrisman for <p>The colors are there but hidden by the indicator borders. Increase their size with</p>
<pre><code>h.set_legend_options(handlelength=1)
</code></pre>
https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36221#post-id-36221Very nice - see also https://trac.sagemath.org/ticket/22151Sun, 08 Jan 2017 05:45:00 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36221#post-id-36221Comment by Acksl for <p>The colors are there but hidden by the indicator borders. Increase their size with</p>
<pre><code>h.set_legend_options(handlelength=1)
</code></pre>
https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36222#post-id-36222Perfect, thanks! :)Sun, 08 Jan 2017 13:28:39 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36222#post-id-36222Comment by tmonteil for <p>The colors are there but hidden by the indicator borders. Increase their size with</p>
<pre><code>h.set_legend_options(handlelength=1)
</code></pre>
https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36223#post-id-36223Great. Should a nonzero value set by default ? Or does this has effect somewhere else ?Sun, 08 Jan 2017 16:38:52 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36223#post-id-36223Comment by kcrisman for <p>The colors are there but hidden by the indicator borders. Increase their size with</p>
<pre><code>h.set_legend_options(handlelength=1)
</code></pre>
https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36232#post-id-36232Probably; http://matplotlib.org/api/legend_api.html#matplotlib.legend.Legend 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."Mon, 09 Jan 2017 16:54:18 +0100https://ask.sagemath.org/question/36210/legend-for-histogram/?comment=36232#post-id-36232