Legend style with axes.hist(histtype='step')

One of the things that bugs me about axes.hist is that with
histtype='step' the automatic legend style is an empty box, instead of
a line, as I would expect. This behaviour doesn't seem to make sense,
because it seems a line would be much more appropriate for this case.
Example is attached for the code:

import matplotlib.pyplot as plt
plt.hist([0,1,1,2,2,2], [0,1,2,3], histtype='step', label="histtype='step'")
plt.legend()
plt.show()

I can get around this by using proxy Line2D objects in building the
legend, but as this is an extremely common operation for me (the
common style of histograms in my field is equivalent to step) this
becomes messy and annoying. I'd rather not have to roll my own
histogram drawing function, as it would be almost entirely duplicating
the axes hist code, and don't know another way to get what I want. I
understand that the way of setting Legend styles is something that has
been looked at recently, but don't know the timescale for any changes.

The cause of this is the fact that in axes.py::7799 (current SVN
head), in axes.hist, patch objects are always created, even for the
line-based step style. I searched the tracker briefly, and couldn't
find this mentioned before. I therefore have a few questions:

- Is this intended behaviour, that I am just not understanding the
requirement for?
- Would changing this to create (and thus return) Line2D's instead of
Patch's for this histtype be a horrible breaking of the return
interface?

I've attached a patch that makes the simple change of swapping out the
call to .fill for .plot (only the function is changed here, not yet
the documentation), and it appears to work but I haven't tested
exhaustively.

Thoughts?

Nick

step_legend.png

histtype_plot.patch (629 Bytes)

As suggested on
http://matplotlib.sourceforge.net/faq/howto_faq.html#submit-a-patch ,
I have submitted this to the patch tracker an am following it up, with
a tracker link! The patch tracker entry is:

https://sourceforge.net/tracker/?func=detail&aid=3178834&group_id=80706&atid=560722

Apologies if I am sticking rigidly (and annoyingly) to this process.
(I have also been observing the git-transition, so appreciate this
probably isn't the best time to integrate random patches)

ยทยทยท

On Mon, Feb 7, 2011 at 1:23 AM, Nicholas Devenish <misnomer+matplotlib@...149...> wrote:

One of the things that bugs me about axes.hist is that with
histtype='step' the automatic legend style is an empty box, instead of
a line, as I would expect. This behaviour doesn't seem to make sense,
because it seems a line would be much more appropriate for this case.
Example is attached for the code:

import matplotlib.pyplot as plt
plt.hist([0,1,1,2,2,2], [0,1,2,3], histtype='step', label="histtype='step'")
plt.legend()
plt.show()

I can get around this by using proxy Line2D objects in building the
legend, but as this is an extremely common operation for me (the
common style of histograms in my field is equivalent to step) this
becomes messy and annoying. I'd rather not have to roll my own
histogram drawing function, as it would be almost entirely duplicating
the axes hist code, and don't know another way to get what I want. I
understand that the way of setting Legend styles is something that has
been looked at recently, but don't know the timescale for any changes.

The cause of this is the fact that in axes.py::7799 (current SVN
head), in axes.hist, patch objects are always created, even for the
line-based step style. I searched the tracker briefly, and couldn't
find this mentioned before. I therefore have a few questions:

- Is this intended behaviour, that I am just not understanding the
requirement for?
- Would changing this to create (and thus return) Line2D's instead of
Patch's for this histtype be a horrible breaking of the return
interface?

I've attached a patch that makes the simple change of swapping out the
call to .fill for .plot (only the function is changed here, not yet
the documentation), and it appears to work but I haven't tested
exhaustively.

Thoughts?

Nick