class histogrammar.primitives.collection.Label(**pairs)[source]

Bases: histogrammar.defs.Factory, histogrammar.defs.Container, histogrammar.primitives.collection.Collection

Accumulate any number of aggregators of the same type and label them with strings. Every sub-aggregator is filled with every input datum.

This primitive simulates a directory of aggregators. For sub-directories, nest collections within the Label collection.

Note that all sub-aggregators within a Label must have the same type (e.g. histograms of different binnings, but all histograms). To collect objects of different types with string-based look-up keys, use UntypedLabel.

To collect aggregators of the same type without naming them, use Index. To collect aggregators of different types without naming them, use Branch.

In strongly typed languages, the restriction to a single type allows nested objects to be extracted without casting.


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


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

Parameters:pairs (list of str, Container pairs) – the collection of aggregators to fill.
Other Parameters:
 entries (float) – the number of entries, initially 0.0.

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


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

static ed(entries, pairsAsDict=None, **pairs)

Create a Label that is only capable of being added.

  • entries (float) – the number of entries.
  • pairs (list of str, Container pairs) – the collection of filled aggregators.

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.


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.


Attempt to get key x, returning None if it does not exist.

getOrElse(x, default)

Attempt to get key x, returning an alternative if it does not exist.

static ing(**pairs)

Synonym for __init__.


Set of keys among the pairs.


Iterable over the keys of the pairs.


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

plot(httpServer=None, **parameters)

Generate a VEGA visualization and serve it via HTTP.


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.


Number of pairs.


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.


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).


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.


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


Iterable over the values of the pairs.


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