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

Skip to content

Commit 29a7d16

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 eaf05e9 commit 29a7d16

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed
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
@@ -2113,12 +2113,6 @@ def make_iterable(x):
21132113

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

lib/matplotlib/tests/test_axes.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,17 +4379,6 @@ def test_rc_major_minor_tick():
43794379
assert yax._minor_tick_kw['tick2On'] == True
43804380

43814381

4382-
@cleanup
4383-
def test_bar_negative_width():
4384-
fig, ax = plt.subplots()
4385-
res = ax.bar(range(1, 5), range(1, 5), width=-1)
4386-
assert len(res) == 4
4387-
for indx, b in enumerate(res):
4388-
assert b._x == indx
4389-
assert b._width == 1
4390-
assert b._height == indx + 1
4391-
4392-
43934382
@cleanup
43944383
def test_square_plot():
43954384
x = np.arange(4)

0 commit comments

Comments
 (0)