Skip to content

FIX: better handle margins on ax.bar #7471

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,55 @@ def make_iterable(x):
raise ValueError("incompatible sizes: argument 'bottom' "
"must be length %d or scalar" % nbars)

margins = {}

if orientation == 'vertical':
# base case of 'simple' bar plot
use_bottom_margin = False
use_top_margin = True
print(use_bottom_margin, use_top_margin)
# if negative height bars, do not pin the bottom
if any(h < 0 for h in height):
use_bottom_margin = True
use_top_margin = True
print(use_bottom_margin, use_top_margin)

# if all bars are negative pin top, but not bottom
if all(h < 0 for h in height):
use_bottom_margin = True
use_top_margin = False

print(use_bottom_margin, use_top_margin)
# if non-trivial bottom, do not pin the bottom
if _bottom is not None:
use_bottom_margin = True
use_top_margin = True
print(use_bottom_margin, use_top_margin)
margins = {'bottom': use_bottom_margin,
'top': use_top_margin}

elif orientation == 'horizontal':
# base case of 'simple' bar plot
use_left_margin = False
use_right_margin = True
# if negative height bars, do not pin the bottom
if any(w < 0 for w in width):
use_left_margin = True
use_right_margin = True

# if all bars are negative pin top, but not bottom
if all(w < 0 for w in width):
use_left_margin = True
use_right_margin = False

# if non-trivial left, do not pin the anything
if _left is not None:
use_left_margin = True
use_right_margin = True

margins = {'left': use_left_margin,
'right': use_right_margin}

patches = []

# lets do some conversions now since some types cannot be
Expand All @@ -2096,13 +2145,6 @@ def make_iterable(x):
if yerr is not None:
yerr = self.convert_yunits(yerr)

margins = {}

if orientation == 'vertical':
margins = {'bottom': False}
elif orientation == 'horizontal':
margins = {'left': False}

if align == 'center':
if orientation == 'vertical':
left = [left[i] - width[i] / 2. for i in xrange(len(left))]
Expand Down