This is definitely a bug, but I thought I'd clarify and add in a little more...
The distinction between 'step' and 'stepfilled' is that 'step' is
supposed to show only the outline of the histogram with no lines in
between bins (standard practice in some fields), while 'stepfilled' is
supposed to do the same, but have a different-colored fill between the
steps and the x-axis. This is different from 'bar' because the bars
always have either an outline bounding each bar, or no outline at all.
An alternative approach, presumably, would be to eliminate
'stepfilled' and instead just pass in some keyword that tells whether
or not to draw the filled color region or not, but that was judged
confusing because it would have no meaning for the bar types.
As for the log=True errors, I think what this was supposed to do was
have the minimum number of bin *counts* be the replacement for 0s,
rather the minimum *value*, so that's just a pure bug. This is might
have been my fault - the code has changed quite a bit from the
original patch, so I'm not sure at this point. The logic was that
this makes more sense than arbitrarily choosing 1 - if you have a
histogram where the bins are all within, say, 1000 and 10000, but one
of them is 0, it perhaps looks better to set the bottom to the 1000
rather than 1... It was really just an arbitrary choice that no one
objected to at the time.
As I think about it, it might make sense to change it so that the log
keyword can be used to set the assumed minimum value for empty bins if
it is greater than 0 (and stick with the default you suggested of 1 if
log=True). The attached patch includes this change, adopted from
Ben's original patch, as well as clarifying all of this in teh
docstring.
On Wed, Aug 11, 2010 at 1:56 PM, Benjamin Root <ben.r...@ou.edu> wrote:
> On Wed, Aug 11, 2010 at 3:11 PM, Benjamin Root <ben.r...@ou.edu> wrote:
>>
>> I am tracing down a bug in hist() and I am trying to figure out what is it
>> about the 'stepfilled' mode that is different from the regular 'bar' mode.
>> Currently, the hist() code has a separate if branch for dealing with 'step'
>> and 'stepfilled', and that branch has a bunch of bugs. The best that I can
>> figure is that it prevents lines from being drawn in between the bins. If
>> that is the only difference, maybe we could somehow use the bar functions?
>>
>> At the very least, I think this needs to be documented better to make it
>> clear why this oddball approach is happening.
>>
>> Thanks,
>> Ben Root
>
> By the way, the bugs I was referring to both have to do with log=True and
> the two stepped modes.
>
> First, the smallest of values to histogram (the minimum bin value) is, for
> some reason, used to clip the lower bounds of the histogram count. In some
> situations, this can result in most if not all the graph not being shown.
>
> Second, related to the first is a problem with the 'stepfilled' mode in log
> space. The stepfilled mode uses the minimum bin value to anchor the
> patches. However, this can cause the polygon to not close correctly and can
> get some unsightly artifacts. I have attached an image demonstrating this
> bug. This has been reported before:
>
> http://old.nabble.com/hist%28%29-with-log-and-step-tp28888742p28888742.html
> http://old.nabble.com/Bug-in-stepfilled-hist-with-log-y-tp28538074p28538074.html
>
> In one of the comments, the reporter concluded that it appeared fixed, but
> either he was experiencing a slightly different problem, or he was mistaken.
>
> I have also included a possible patch for addressing these issues. The
> approach simply sets the minimum value to be zero when not doing log, and
> use 1.0 when log=True. This differs slightly from how the normal bar graphs
> are done where a value of 1e-100 is used when log=True, but then the axes
> limits are adjusted to use 1.0 as a lower limit.
>
> Cheers,
> Ben Root
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
--
Erik Tollerud
Index: lib/matplotlib/legend.py
===================================================================
--- lib/matplotlib/legend.py (revision 8655)
+++ lib/matplotlib/legend.py (working copy)
@@ -253,6 +253,15 @@
# introduce y-offset for handles of the scatter plot
if scatteryoffsets is None:
+ if scatterpoints<2:
+ self._scatteryoffsets = np.array([.5])
+ elif scatterpoints==2:
+ self._scatteryoffsets = np.array([.5,.5])
+ elif scatterpoints==3:
+ self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.])
+ else:
+ self._scatteryoffsets = np.ones(scatterpoints)*(3./8.)
+ self._scatteryoffsets[1::2] = 4./8.
self._scatteryoffsets = np.array([3./8., 4./8., 2.5/8.])
else:
self._scatteryoffsets = np.asarray(scatteryoffsets)
@@ -446,6 +455,7 @@
"""
fontsize = self._fontsize
+ markerscale = self.markerscale
# legend_box is a HPacker, horizontally packed with
# columns. Each column is a VPacker, vertically packed with
@@ -554,14 +564,13 @@
elif isinstance(handle, RegularPolyCollection):
- #ydata = self._scatteryoffsets
ydata = height*self._scatteryoffsets
size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\
min(handle.get_sizes())*self.markerscale**2
if self.scatterpoints < 4:
- sizes = [.5*(size_max+size_min), size_max,
- size_min]
+ sizes = np.array([.5*(size_max+size_min), size_max,
+ size_min])
else:
sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min
@@ -585,12 +594,12 @@
size_max, size_min = max(handle.get_sizes())*self.markerscale**2,\
min(handle.get_sizes())*self.markerscale**2
if self.scatterpoints < 4:
- sizes = [.5*(size_max+size_min), size_max,
- size_min]
+ sizes = np.array([.5*(size_max+size_min), size_max,
+ size_min])
else:
sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min
- p = type(handle)(sizes,
+ p = type(handle)(sizes*markerscale,
offsets=zip(xdata_marker,ydata),
transOffset=self.get_transform(),
)
Index: lib/matplotlib/axes.py
===================================================================
--- lib/matplotlib/axes.py (revision 8655)
+++ lib/matplotlib/axes.py (working copy)
@@ -7492,11 +7492,14 @@
- 'barstacked' is a bar-type histogram where multiple
data are stacked on top of each other.
- - 'step' generates a lineplot that is by default
- unfilled.
+ - 'step' is a histogram outlined by a lineplot with unfilled
+ patches. Toutlines only follow the top of the histogram, and
+ hence *rwidth* has no effect.
- - 'stepfilled' generates a lineplot that is by default
- filled.
+ - 'stepfilled' is a histogram bounded by a lineplot with filled
+ patches underneath. This is distinct from 'bar' in that the
+ outlines only follow the top of the histogram, and hence
+ *rwidth* has no effect.
*align*: ['left' | 'mid' | 'right' ]
Controls how the histogram is plotted.
@@ -7521,7 +7524,9 @@
If *True*, the histogram axis will be set to a log scale.
If *log* is *True* and *x* is a 1D array, empty bins will
be filtered out and only the non-empty (*n*, *bins*,
- *patches*) will be returned.
+ *patches*) will be returned. If *histtype* is 'step' or
+ 'stepfilled', this can also be a float>0 specifying the value to
+ assign to empty bins.
*color*:
Color spec or sequence of color specs, one per
@@ -7720,9 +7725,14 @@
y = np.zeros( 2*len(bins), np.float )
x[0::2], x[1::2] = bins, bins
+
+ if log is true:
+ minimum = 1.0
+ elif log:
+ minimum = float(log)
+ else:
+ minimum = 0.0
- minimum = min(bins)
-
if align == 'left' or align == 'center':
x -= 0.5*(bins[1]-bins[0])
elif align == 'right':
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel