New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make hist with 'step' histtype draw Line2D instead of Patch #233
Comments
The patch is lost, but the idea is simple and the questions it raises are valid. This needs to be reviewed and either rejected or implemented. |
I think stepped histograms do return Line2D objects presently (at least in 1.3.x), so maybe this has magically been resolved in the meantime? |
I tried the example from the original report, and it still produced a box instead of a line in the legend. |
My bad -- I was just confused. Move along... ;) |
@neggert As you have been poking at the histogram code recently, have you looked at this issue? |
I haven't, but do we really want |
As I user, I would answer yes to @neggert's question - I almost always have to leave histograms off legends (or make a "fake" legend entry by plotting outside the axes box), as I almost always want 'step' mode but find that the box in the legend is endlessly confusing to people I show the plots to. |
@eteq If that is the case, than use |
@tacaswell - the value of |
Would it be sensible to add a function |
That would certainly work for me, and is probably a better scheme than the current |
There's going to be a lot of code duplication between I guess I should also note that I prefer the outlined empty box (the current state) in the legend to just a line (the proposed change), although not strongly. If we make the proposed change, what do we do with the legend for a filled step histogram? I think that should definitely stay as it is. |
Maybe add a |
Issue #827 might also be of interest to this discussion. |
Closing this as it has been dead for almost a year and is originally from 2011. The fundamental problem is that the return type of |
Is there any example on how to make it plot with lines instead of empty boxes? The only reference I could find was https://stackoverflow.com/questions/19988556/how-to-use-alternative-legend-handler-for-histogram. |
This is still bothering me in 2019. |
There is a working solution here: https://stackoverflow.com/questions/47490586/change-the-legend-format-of-python-histogram. |
Original report at SourceForge, opened Fri Feb 11 22:02:28 2011
One of the annoying things 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 code to demonstrate this:
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()
With the current uncustomisability of legend styles one can get around this by using proxy Line2D objects in building the legend, but this can be a common operation and becomes messy and annoying.
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, and couldn't find this mentioned before.
Attached is a patch that makes the very 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?
SourceForge History
The text was updated successfully, but these errors were encountered: