FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Axes.hist: use bottom for minimum if log and histtype='step...' by duncanmmacleod · Pull Request #4608 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .png  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion lib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5909,7 +5909,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
logbase = self.yaxis._scale.base

# Setting a minimum of 0 results in problems for log plots
if normed or weights is not None:
if np.min(bottom) > 0:
minimum = np.min(bottom)
elif normed or weights is not None:
# For normed data, set to log base * minimum data value
# (gives 1 full tick-label unit for the lowest filled bin)
ndata = np.array(n)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,30 @@ def test_hist_steplog():
plt.hist(data_big, 100, histtype='stepfilled', log=True, orientation='horizontal')


@image_comparison(baseline_images=['hist_step_log_bottom'],
remove_text=True, extensions=['png'])
def test_hist_step_log_bottom():
# check that bottom doesn't get overwritten by the 'minimum' on a
# log scale histogram (https://github.com/matplotlib/matplotlib/pull/4608)
np.random.seed(0)
data = np.random.standard_normal(2000)
fig = plt.figure()
ax = fig.add_subplot(111)
# normal hist (should clip minimum to 1/base)
ax.hist(data, bins=10, log=True, histtype='stepfilled',
alpha=0.5, color='b')
# manual bottom < 1/base (previously buggy, see #4608)
ax.hist(data, bins=10, log=True, histtype='stepfilled',
alpha=0.5, color='g', bottom=1e-2)
# manual bottom > 1/base
ax.hist(data, bins=10, log=True, histtype='stepfilled',
alpha=0.5, color='r', bottom=0.5)
# array bottom with some less than 1/base (should clip to 1/base)
ax.hist(data, bins=10, log=True, histtype='stepfilled',
alpha=0.5, color='y', bottom=np.arange(10))
ax.set_ylim(9e-3, 1e3)


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

Back | FazBrowse Home | New Git URL