From 90f8807de106f8e19cc05ed36f7cf4b40595ec9d Mon Sep 17 00:00:00 2001 From: Adam Ginsburg Date: Fri, 20 Jul 2012 14:25:53 -0600 Subject: [PATCH 1/2] Implemented fix to issue 196 on github for log=True and histtype='step' --- lib/matplotlib/axes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 82def00583ed..f6e73b506df8 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7861,7 +7861,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, x[0::2], x[1::2] = bins, bins - minimum = min(bins) + ndata = np.array(n) + minimum = (ndata[ndata>0].min())*0.1 if align == 'left' or align == 'center': x -= 0.5*(bins[1]-bins[0]) From f888a2650afd9a2391a5691710d000eadc5d87f4 Mon Sep 17 00:00:00 2001 From: Adam Ginsburg Date: Fri, 20 Jul 2012 15:14:42 -0600 Subject: [PATCH 2/2] fixed the minimum specification in ax.hist as per @WeatherGod's comment; only want to set min this way if log is specified. Also, added case for normed vs not --- lib/matplotlib/axes.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index f6e73b506df8..d2f48855343a 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7861,8 +7861,19 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, x[0::2], x[1::2] = bins, bins - ndata = np.array(n) - minimum = (ndata[ndata>0].min())*0.1 + if log: + # setting a minimum of 0 results in problems for log plots + if normed: + # for normed data, set to 0.1 * minimum data value + # (gives 1 full dex for the lowest filled bin) + ndata = np.array(n) + minimum = (ndata[ndata>0].min())*0.1 + else: + # for non-normed data, set the min to 0.1, again so that + # there is 1 full dex for the lowest bin + minimum = 0.1 + else: + minimum = min(bins) if align == 'left' or align == 'center': x -= 0.5*(bins[1]-bins[0])