Add functionality to plot bar and barh with string labels (Implement #2516)#4266
Add functionality to plot bar and barh with string labels (Implement #2516)#4266tacaswell merged 1 commit intomatplotlib:masterfrom umairidris:bar_labels
Conversation
|
The Travis docs build failure is not an issue with this Pull request. Fixed by #4267 |
There was a problem hiding this comment.
I would do this as [i + h / 2 for i, h in enumerate(height)], same for the logic in bar
There was a problem hiding this comment.
Thanks, this looks a lot better now! Fixed via 1627e8e
|
👍 for the idea, I am a bit wary of overloading |
You're right. To address this I added a check and raised ValueError if bottom (bar) or left (barh) are a list of strings. Perhaps we should more explicitly state this in the docstring as well. If you have any suggestions on how to improve this let me know! |
|
Sorry, I transposed the issue. Now you can't specify both the labels and non-unit bar spacing which is much worse. |
|
Ah, I see what you mean. Perhaps a better way to do this is to not touch left and bottom and instead add an extra kwarg 'labels' or something similar? The use case I am thinking about is: bar([1,2,3], [1,1,1], labels=['a', 'b', 'c']) |
|
Yes, I think that is a better route. I would also not move the ticks relative to the bar unless explicitly asked to. Both |
|
@umairidris You should also have a look at how boxplot handles this sort of thing. iirc |
|
Thanks for the feedback and advice @tacaswell! I have addressed it via commit c04bf79. A few points I should mention:
I hope I addressed your concerns. Please let me know if you have any further suggestions! |
|
This looks good, just one code comment. Can you add an entry in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new so that this gets advertised? |
There was a problem hiding this comment.
I would do this as
label_ticks_flag = not tick_label is NoneWhich I think is a bit clearer.
There was a problem hiding this comment.
tick_label is not None, please
On Mar 29, 2015 11:33 PM, "Thomas A Caswell" notifications@github.com
wrote:
In lib/matplotlib/axes/_axes.py
#4266 (comment):@@ -1926,6 +1930,8 @@ def make_iterable(x):
width = make_iterable(width)
_bottom = bottom
bottom = make_iterable(bottom)
_tick_label = tick_labelI would do this as
label_ticks_flag = not tick_label is None
Which I think is a bit clearer.
—
Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/4266/files#r27365250.
|
@umairidris This needs to be rebased, not sure why. |
|
@tacaswell Done! My branch had the old docstrings (not numpy format) which was causing merge conflicts. All fixed now. :) Umair I. |
|
Great. I will merge this as soon as travis passes again. |
ENH : pass list of strings to label bar/barh plots Add functionality to plot bar and barh to label bars with list strings (closes #2516)
This patch is an attempt to add the functionality to pass in strings to label the axis of a bar graph (issue #2516). The patch shouldn't break any existing API. I also center the labels based on the width/height passed for a cleaner more professional look (please view the tests). I am happy to hear any feedback and/or concerns!
Cheers!
Umair