histogrammar.primitives.bin.Bin

class histogrammar.primitives.bin.Bin(num, low, high, quantity, value=<Count 0.0>, underflow=<Count 0.0>, overflow=<Count 0.0>, nanflow=<Count 0.0>)[source]

Bases: histogrammar.defs.Factory, histogrammar.defs.Container

Split a quantity into equally spaced bins between a low and high threshold and fill exactly one bin per datum.

When composed with Count, this produces a standard histogram:

Bin.ing(100, 0, 10, fill_x, Count.ing())

and when nested, it produces a two-dimensional histogram:

Bin.ing(100, 0, 10, fill_x,
  Bin.ing(100, 0, 10, fill_y, Count.ing()))

Combining with [Deviate](#deviate-mean-and-variance) produces a physicist’s “profile plot:”

Bin.ing(100, 0, 10, fill_x, Deviate.ing(fill_y))

and so on.

__add__(other)

Add two containers of the same type. The originals are unaffected.

__init__(num, low, high, quantity, value=<Count 0.0>, underflow=<Count 0.0>, overflow=<Count 0.0>, nanflow=<Count 0.0>)

Create a Bin that is capable of being filled and added.

Parameters:
  • num (int) – the number of bins; must be at least one.
  • low (float) – the minimum-value edge of the first bin.
  • high (float) – the maximum-value edge of the last bin; must be strictly greater than low.
  • quantity (function returning float) – computes the quantity of interest from the data.
  • value (Container) – generates sub-aggregators to put in each bin.
  • underflow (Container) – a sub-aggregator to use for data whose quantity is less than low.
  • overflow (Container) – a sub-aggregator to use for data whose quantity is greater than or equal to high.
  • nanflow (Container) – a sub-aggregator to use for data whose quantity is NaN.
Other Parameters:
 
  • entries (float) – the number of entries, initially 0.0.
  • values (list of Container) – the sub-aggregators in each bin.
ascii()

Prints ascii histogram, for debuging on headless machines

bin(x)

Find the bin index associated with numerical value x.

@return -1 if x is out of range; the bin index otherwise.

children

List of sub-aggregators, to make it possible to walk the tree.

copy()

Copy this container, making a clone with no reference to the original.

static ed(low, high, entries, values, underflow, overflow, nanflow)

Create a Bin that is only capable of being added.

Parameters:
  • low (float) – the minimum-value edge of the first bin.
  • high (float) – the maximum-value edge of the last bin; must be strictly greater than low.
  • entries (float) – the number of entries.
  • values (list of Container) – the filled sub-aggregators, one for each bin.
  • underflow (Container) – the filled underflow bin.
  • overflow (Container) – the filled overflow bin.
  • nanflow (Container) – is the filled nanflow bin.
factory

Reference to the container’s factory for runtime reflection.

fill(datum, weight=1.0)

Increment the aggregator by providing one datum to the fill rule with a given weight.

Usually all containers in a collection of histograms take the same input data by passing it recursively through the tree. Quantities to plot are specified by the individual container’s lambda functions.

The container is changed in-place.

fromJson(json)

User’s entry point for reconstructing a container from JSON text.

static fromJsonFragment(json, nameFromParent)

staticmethod(function) -> method

Convert a function to be a static method.

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C: def f(arg1, arg2, ...): ... f = staticmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see the classmethod builtin.

histogram()

Return a plain histogram by converting all sub-aggregator values into Counts.

indexes

Get a sequence of valid indexes.

static ing(num, low, high, quantity, value=<Count 0.0>, underflow=<Count 0.0>, overflow=<Count 0.0>, nanflow=<Count 0.0>)

Synonym for __init__.

name

Name of the concrete Factory as a string; used to label the container type in JSON.

nan(x)

Return true iff x is in the nanflow region (equal to NaN).

num

Number of bins.

over(x)

Return true iff x is in the overflow region (greater than high).

plot(httpServer=None, **parameters)

Generate a VEGA visualization and serve it via HTTP.

range(index)

Get the low and high edge of a bin (given by index number).

register(factory)

Add a new Factory to the registry, introducing a new container type on the fly. General users usually wouldn’t do this, but they could. This method is used internally to define the standard container types.

specialize()

Explicitly invoke histogrammar.specialized.addImplicitMethods on this object, usually right after construction (in each of the methods that construct: __init__, ed, ing, fromJsonFragment, etc).

Objects used as default parameter arguments are created too early for this to be possible, since they are created before the histogrammar.specialized module can be defined. These objects wouldn’t satisfy any of addImplicitMethod‘s checks anyway.

toImmutable()

Return a copy of this container as though it was created by the ed function or from JSON (the “immutable form” in languages that support it, not Python).

toJson()

Convert this container to dicts and lists representing JSON (dropping its fill method).

Note that the dicts and lists can be turned into a string with json.dumps.

toJsonFragment(suppressName)

Used internally to convert the container to JSON without its "type" header.

under(x)

Return true iff x is in the underflow region (less than low).

zero()

Create an empty container with the same parameters as this one. The original is unaffected.