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

Skip to content

Set sticky_edges correctly for negative height bar(). #7995

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

Merged
merged 2 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
`bar` now returns rectangles of negative height or width if the corresponding input is negative
```````````````````````````````````````````````````````````````````````````````````````````````

`plt.bar` used to normalize the coordinates of the rectangles that it created,
to keep their height and width positives, even if the corresponding input was
negative. This normalization has been removed to permit a simpler computation
of the correct `sticky_edges` to use.
6 changes: 0 additions & 6 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2114,12 +2114,6 @@ def make_iterable(x):

args = zip(left, bottom, width, height, color, edgecolor, linewidth)
for l, b, w, h, c, e, lw in args:
if h < 0:
b += h
h = abs(h)
if w < 0:
l += w
w = abs(w)
r = mpatches.Rectangle(
xy=(l, b), width=w, height=h,
facecolor=c,
Expand Down
10 changes: 0 additions & 10 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4388,16 +4388,6 @@ def test_rc_major_minor_tick():
assert yax._minor_tick_kw['tick2On'] == True


def test_bar_negative_width():
fig, ax = plt.subplots()
res = ax.bar(range(1, 5), range(1, 5), width=-1)
assert len(res) == 4
for indx, b in enumerate(res):
assert b._x == indx
assert b._width == 1
assert b._height == indx + 1


def test_square_plot():
x = np.arange(4)
y = np.array([1., 3., 5., 7.])
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def test_rotate_rect():
assert_almost_equal(rect1.get_verts(), new_verts)


def test_negative_rect():
# These two rectangles have the same vertices, but starting from a
# different point. (We also drop the last vertex, which is a duplicate.)
pos_vertices = Rectangle((-3, -2), 3, 2).get_verts()[:-1]
neg_vertices = Rectangle((0, 0), -3, -2).get_verts()[:-1]
assert_array_equal(np.roll(neg_vertices, 2, 0), pos_vertices)


@image_comparison(baseline_images=['clip_to_bbox'])
def test_clip_to_bbox():
fig = plt.figure()
Expand Down