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

Skip to content

Commit da7564d

Browse files
committed
Set sticky_edges correctly for negative height bar().
The patch correctly sets the sticky edge to 0 instead of -1 for `bar(0, height=-1)`.
1 parent 0cab7c6 commit da7564d

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
`bar` now returns rectangles of negative height or width if the corresponding input is negative
2+
```````````````````````````````````````````````````````````````````````````````````````````````
3+
4+
`plt.bar` used to normalize the coordinates of the rectangles that it created,
5+
to keep their height and width positives, even if the corresponding input was
6+
negative. This normalization has been removed to permit a simpler computation
7+
of the correct `sticky_edges` to use.

lib/matplotlib/axes/_axes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,12 +2114,6 @@ def make_iterable(x):
21142114

21152115
args = zip(left, bottom, width, height, color, edgecolor, linewidth)
21162116
for l, b, w, h, c, e, lw in args:
2117-
if h < 0:
2118-
b += h
2119-
h = abs(h)
2120-
if w < 0:
2121-
l += w
2122-
w = abs(w)
21232117
r = mpatches.Rectangle(
21242118
xy=(l, b), width=w, height=h,
21252119
facecolor=c,

lib/matplotlib/tests/test_axes.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,16 +4388,6 @@ def test_rc_major_minor_tick():
43884388
assert yax._minor_tick_kw['tick2On'] == True
43894389

43904390

4391-
def test_bar_negative_width():
4392-
fig, ax = plt.subplots()
4393-
res = ax.bar(range(1, 5), range(1, 5), width=-1)
4394-
assert len(res) == 4
4395-
for indx, b in enumerate(res):
4396-
assert b._x == indx
4397-
assert b._width == 1
4398-
assert b._height == indx + 1
4399-
4400-
44014391
def test_square_plot():
44024392
x = np.arange(4)
44034393
y = np.array([1., 3., 5., 7.])

0 commit comments

Comments
 (0)