Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suggesting new feature: autolabel option for bar plots #12386

Closed
@ebauch

Description

@ebauch

Whenever I plot some form of bar plot I find myself thinking that it would be nice to have the bars labelled with the actual value counts (or a percentage value). Examples are given in the barplot gallery:

image

image

This is the code that makes it happen:

# label bars
def autolabel(rects):
    for ii,rect in enumerate(rects):
        height = rect.get_height()
        plt.text(rect.get_x()+rect.get_width()/2., 1.02*height, '%s'% (mean_values[ii]),
            ha='center', va='bottom')
autolabel(rects)

I think this feature is so crucial that it should be part of barplot via an argument such as autolabel = true or something. What do people think? Implementing this would be relatively easy I suppose but edge cases (such as error bars) might be harder to deal with. I find myself spending quite some time adjusting the heights and axis limits to make it all fit together - automating this would be a big plus.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions