# Question about legend on histogram plot

Hello,

Consider these two simple lines in IPython -pylab:
plt.hist(np.random.randn(1000), normed=1, histtype='step', label='test', lw=2)
plt.legend()

How could I change the appearance of the legend symbol in this case?
It auto-uses a patch object (rectangle in this case).
I would like to get a straight line instead.

Thanks.

···

--
Gökhan

You may use proxy artists.

http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist

Regards,

-JJ

···

On Thu, Oct 21, 2010 at 4:31 AM, Gökhan Sever <gokhansever@...287...> wrote:

How could I change the appearance of the legend symbol in this case?
It auto-uses a patch object (rectangle in this case).
I would like to get a straight line instead.

Thanks for the suggestion JJ.

I have actually changed my initial approach. Now I am just using
colored text to create pseudo-legends, like shown below:

ax1.text(0.40, 0.8, "Cloud-base", fontsize=14, transform=ax1.transAxes)
ax1.text(0.40, 0.7, "BallVario", fontsize=14, color='b',
transform=ax1.transAxes)
ax1.text(0.40, 0.6, "AIMMS", fontsize=14, color='g', transform=ax1.transAxes)

By the way, from the linked construct, changing width and height of
the rectangle doesn't have any affect.

p = Rectangle((0, 0), 1, 1, fc="r")
legend([p], ["Red Rectangle"])

p = Rectangle((0, 0), 10.0, 2.0, fc="r")
plt.legend([p], ["Red Rectangle"])

or making trying a smaller rectangle:

p = Rectangle((0, 0), 0.2, 1, fc="r")
plt.figure(); plt.legend([p], ["Red Rectangle"])

···

On Fri, Oct 22, 2010 at 6:26 AM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

On Thu, Oct 21, 2010 at 4:31 AM, Gökhan Sever <gokhansever@...287...> wrote:

How could I change the appearance of the legend symbol in this case?
It auto-uses a patch object (rectangle in this case).
I would like to get a straight line instead.

You may use proxy artists.

http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist

Regards,

-JJ

--
Gökhan

This is an expected behavior. Legend handles only respect a subset of
parent's properties. For example, for lines, the lengths of the legend
handles are not associated with the lengths of the original lines.

While it would be better if one can customize such properties, such
functionality is not currently implemented.

Regards,

-JJ

···

On Sat, Oct 23, 2010 at 1:30 AM, Gökhan Sever <gokhansever@...287...> wrote:

By the way, from the linked construct, changing width and height of
the rectangle doesn't have any affect.