Skip to content
Closed
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
8 changes: 0 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6378,14 +6378,6 @@ def _normalize_input(inp, ename='input'):
p.update(kwargs)
p.set_label('_nolegend_')

if binsgiven:
if orientation == 'vertical':
self.update_datalim(
[(bins[0], 0), (bins[-1], 0)], updatey=False)
else:
self.update_datalim(
[(0, bins[0]), (0, bins[-1])], updatex=False)

if nx == 1:
return n[0], bins, cbook.silent_list('Patch', patches[0])
else:
Expand Down
33 changes: 33 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import datetime

from itertools import product

import pytz

import numpy as np
Expand Down Expand Up @@ -1196,6 +1198,37 @@ def test_hist_step_log_bottom():
ax.set_ylim(9e-3, 1e3)


@cleanup
def test_hist_datalims_binsgiven():
# Checks that the hist function updates axes' dataLim to minimum and maximum
# bins if the latter are given explicitly as a sequence.
# Helper function that runs actual tests
@cleanup
def do_test(histtype, orientation, stacked):
# Random values between -1 and 1
x1 = 2*np.random.randn(10)-1
# Random values between -5 and 5
x2 = 10*np.random.randn(10)-5
# Plot histogram with explicitly given bins from -3 to 3
plt.hist([x1, x2], bins=[-3, -2, -1, 0, 1, 2, 3], histtype=histtype,
orientation=orientation, stacked=stacked)
# Check that dataLim is given by bin range and not by data range
if orientation == "horizontal":
assert_equal(plt.gca().dataLim.y0, -3)
assert_equal(plt.gca().dataLim.y1, 3)
elif orientation == "vertical":
assert_equal(plt.gca().dataLim.x0, -3)
assert_equal(plt.gca().dataLim.x1, 3)
# Test generation
np.random.seed(0)
histtypes = [ "bar", "step", "stepfilled" ]
orientations = [ "horizontal", "vertical" ]
stacked = [ True, False ]
all_combinations = product(histtypes, orientations, stacked)
for histtype, orientation, stacked in all_combinations:
yield do_test, histtype, orientation, stacked


def contour_dat():
x = np.linspace(-3, 5, 150)
y = np.linspace(-3, 5, 120)
Expand Down