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

Skip to content

Commit 349d6f0

Browse files
authored
Merge pull request #7995 from anntzer/negative-height-bar
Set sticky_edges correctly for negative height bar().
2 parents ccc8f16 + 6b25f0b commit 349d6f0

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
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
@@ -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
@@ -4436,16 +4436,6 @@ def test_rc_major_minor_tick():
44364436
assert yax._minor_tick_kw['tick2On']
44374437

44384438

4439-
def test_bar_negative_width():
4440-
fig, ax = plt.subplots()
4441-
res = ax.bar(range(1, 5), range(1, 5), width=-1)
4442-
assert len(res) == 4
4443-
for indx, b in enumerate(res):
4444-
assert b._x == indx
4445-
assert b._width == 1
4446-
assert b._height == indx + 1
4447-
4448-
44494439
def test_square_plot():
44504440
x = np.arange(4)
44514441
y = np.array([1., 3., 5., 7.])

lib/matplotlib/tests/test_patches.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def test_rotate_rect():
8383
assert_almost_equal(rect1.get_verts(), new_verts)
8484

8585

86+
def test_negative_rect():
87+
# These two rectangles have the same vertices, but starting from a
88+
# different point. (We also drop the last vertex, which is a duplicate.)
89+
pos_vertices = Rectangle((-3, -2), 3, 2).get_verts()[:-1]
90+
neg_vertices = Rectangle((0, 0), -3, -2).get_verts()[:-1]
91+
assert_array_equal(np.roll(neg_vertices, 2, 0), pos_vertices)
92+
93+
8694
@image_comparison(baseline_images=['clip_to_bbox'])
8795
def test_clip_to_bbox():
8896
fig = plt.figure()

0 commit comments

Comments
 (0)