In [1]:
from __future__ import print_function
import pytest
import os, sys
import numpy as np

sys.path.insert(0, os.path.abspath('../../..'))
import hublib.rappture as rappture
from hublib import ureg, Q_

Histogram Example

This code loads in the output of a run from the Rappture zoo of examples.

https://nanohub.org/infrastructure/rappture/browser/trunk/examples/zoo/histogram


In [2]:
io = rappture.RapXML('hist_run.xml')

In [3]:
io


Out[3]:

INPUTS

PathLabelDescription
input.integer(points)Number of pointsDetermines the number of data points in

OUTPUTS

PathLabelDescription
output.histogram(example)Single datasetThis is an example of a single histogram
output.histogram(single)Single histogramThis is an example of a single histogram
output.histogram(multi1.8)Factor a=1.8This is an example of a multiple histogr
output.histogram(multi2)Factor a=2This is an example of a multiple histogr
output.histogram(namevalue)Name value histogramThis is an example of a name value histo
output.histogram(width)Variable-Width histogramThis is an example of an histogram

In [4]:
%matplotlib notebook
io['output.histogram(example)'].plot()


Here is what Rappture outputs:


In [5]:
io['output.histogram(example)'].xml()


Out[5]:
<histogram id="example">
            <about>
                <label>Single dataset</label>
                <description>This is an example of a single histogram.</description>
            </about>
            <xaxis>
                <label>Time</label>
                <description>Time during the experiment.</description>
                <units>s</units>
                <marker>
                    <at>5</at>
                    <label>Look here</label>
                    <style>-foreground red -linewidth 2</style>
                </marker>
            </xaxis>
            <yaxis>
                <label>Voltage v(11)</label>
                <description>Output from the amplifier.</description>
                <units>V</units>
            </yaxis>
            <component>
                <xy>1 0.99
       2 0.34
       4 0.57
       6 0.22
       7 0.11</xy>
            </component>
        </histogram>
        

In [6]:
io['output.histogram(single)'].plot()


Here is Rappture's output for the same data:

Just like Curves, Histograms can have a group id, so they can be plotted together. Here they are seperated


In [7]:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1,2)
io['output.histogram(multi1.8)'].plot(single=True, ax=axs[0])
io['output.histogram(multi2)'].plot(single=True, ax=axs[1])


Plot them both together like this:


In [8]:
io['output.histogram(multi2)'].plot()


If you prefer them stacked...


In [9]:
io['output.histogram(multi2)'].plot(stacked=True)


Here is what Rappture does, which seems VERY wrong. It looks like a stacked barchart, but the heights do not add up. Its behavior for multiple histograms is actually not documented, so maybe it is a feature. This example is from the zoo examples.


In [10]:
io['output.histogram(namevalue)'].plot(horizontal=True)



In [11]:
io['output.histogram(width)'].plot()