Skip to content

bars in plt.bar graph centered on "left" value #8882

Closed

Description

@skjaeve

Bug report

Bug summary

Docstring for plt.bar:

matplotlib.pyplot.bar(left, height, width=0.8, bottom=None, hold=None, data=None, **kwargs)
Make a bar plot.

Make a bar plot with rectangles bounded by:

left, left + width, bottom, bottom + height
(left, right, bottom and top edges)

However, "left" is in fact the center value of the resulting bars.

Code for reproduction

# Paste your code here
#
#
import numpy as np
import matplotlib.pyplot as plt
lefts = np.asarray((0, 100, 200, 300, 400))
plt.bar(left=lefts, height=lefts, width=100)
plt.bar(left=lefts, height=lefts, width=75)
plt.bar(left=lefts, height=lefts, width=50)
plt.bar(left=lefts, height=lefts, width=25)

Actual outcome
mwe-bar

# If applicable, paste the console output here
#
#

Expected outcome
Bars should be left-aligned to the "left" value.
As the attached plot shows: Bars are centered on "left" value, and not left-aligned to it.

Matplotlib version

  • Operating System: Fedora Linux 26
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6
  • Jupyter Version (if applicable):
  • Other Libraries:

matplotlib installed using pip

Activity

  1. QuLogic commented on Jul 15, 2017

    @QuLogic
    Member

    This is expected, if odd behaviour; left cannot be renamed to center due to API compatibility. See #7954.

  2. skjaeve commented on Jul 15, 2017

    @skjaeve
    Author
  3. WeatherGod commented on Jul 15, 2017

    @WeatherGod
    Member
  4. QuLogic commented on Jul 15, 2017

    @QuLogic
    Member

    It doesn't exactly say it's the default, but it does say that the rectangles will be (left, left+width) which is not quite correct when it's centred.

  5. skjaeve commented on Jul 17, 2017

    @skjaeve
    Author

    The first paragraph in the function documentation says:

    Make a bar plot with rectangles bounded by:

    left, left + width, bottom, bottom + height
    (left, right, bottom and top edges)

    which clearly implies that "left" is in fact the left edges of the drawn rectangles. If this can't be fixed easily, please at least update the first paragraph of the documentation to explain the "align" keyword.

  6. WeatherGod commented on Jul 17, 2017

    @WeatherGod
    Member
  7. added 4 commits that reference this issue on Aug 27, 2017
    5dc4071
    e8f6cdc
    674dce4
    e078f91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions