Example #1
0
def test_bars_one_magnitude():
    numpy.random.seed(1234)
    observations = numpy.random.normal(loc=1, size=(25, 100))
    y = numpy.mean(observations, axis=1)

    canvas, axes, mark = toyplot.bars(y)
    assert_canvas_matches(canvas, "bars-one-magnitude")
Example #2
0
def test_bars_one_magnitude():
    numpy.random.seed(1234)
    observations = numpy.random.normal(loc=1, size=(25, 100))
    y = numpy.mean(observations, axis=1)

    canvas, axes, mark = toyplot.bars(y)
    assert_canvas_matches(canvas, "bars-one-magnitude")
Example #3
0
def test_axes_bars_boundaries_masked_nan():
    numpy.random.seed(1234)
    observations = numpy.random.normal(size=(50, 50))
    b = numpy.ma.column_stack((numpy.min(observations, axis=1), numpy.median(
        observations, axis=1), numpy.max(observations, axis=1)))
    b[10:20, 0] = numpy.nan
    b[30:40, 1] = numpy.ma.masked
    b[20:30, 2] = numpy.nan

    canvas, axes, mark = toyplot.bars(b, baseline=None)
    assert_canvas_matches(canvas, "axes-bars-boundaries-masked-nan")
Example #4
0
def test_axes_bars_boundaries_masked_nan():
    numpy.random.seed(1234)
    observations = numpy.random.normal(size=(50, 50))
    b = numpy.ma.column_stack((numpy.min(observations, axis=1), numpy.median(
        observations, axis=1), numpy.max(observations, axis=1)))
    b[10:20, 0] = numpy.nan
    b[30:40, 1] = numpy.ma.masked
    b[20:30, 2] = numpy.nan

    canvas, axes, mark = toyplot.bars(b, baseline=None)
    assert_canvas_matches(canvas, "axes-bars-boundaries-masked-nan")
Example #5
0
def test_axes_bars_magnitudes_masked_nan():
    x = numpy.linspace(0, 2 * numpy.pi, 51)
    y = numpy.ma.column_stack((
        1 + 0.5 * numpy.sin(x),
        1 + 0.5 * numpy.cos(x),
        1 + 0.2 * numpy.sin(2 * x),
    ))
    y[8:18, 0] = numpy.nan
    y[33:43, 1] = numpy.ma.masked

    canvas, axes, mark = toyplot.bars(x, y)
    assert_canvas_matches(canvas, "axes-bars-magnitudes-masked-nan")
Example #6
0
def test_axes_bars_magnitudes_masked_nan():
    x = numpy.linspace(0, 2 * numpy.pi, 51)
    y = numpy.ma.column_stack((
        1 + 0.5 * numpy.sin(x),
        1 + 0.5 * numpy.cos(x),
        1 + 0.2 * numpy.sin(2 * x),
    ))
    y[8:18, 0] = numpy.nan
    y[33:43, 1] = numpy.ma.masked

    canvas, axes, mark = toyplot.bars(x, y)
    assert_canvas_matches(canvas, "axes-bars-magnitudes-masked-nan")
Example #7
0
def ElectricityorGasPlotter(state, resource, zipcode=None):
    cp = toyplot.color.Palette()
    cpalpha = []
    for i in cp:
        i['a'] = 0.4
        cpalpha.append(i)
    colors = [cp[0], cpalpha[0], cp[1], cpalpha[1], cp[2], cpalpha[2]]

    if len(zipcode) != 5:
        zipcode = None
    if zipcode != None:
        j = requestmaker(
            api_url='cleap/v1/energy_expenditures_and_ghg_by_sector',
            source='NREL',
            zipcode=zipcode)
        geo = zipcode
    elif zipcode == None:
        state_abrev = us_state_abbrev[state]
        geo = state_abrev
        j = requestmaker(
            api_url='cleap/v1/energy_expenditures_and_ghg_by_sector',
            source='NREL',
            state=state_abrev)

    r = j['result'][list(j['result'].keys())[0]]
    labels = [
        f'{geo} Res.', 'US Res.', f'{geo} Com.', 'US Com.', f'{geo} Ind.',
        'US Ind.'
    ]
    if resource == 'Elec':
        i_res_elec = r['residential']['elec_mwh'] / r['residential'][
            'total_pop']
        i_com_elec = r['commercial']['elec_mwh'] / r['residential']['total_pop']
        i_ind_elec = r['industrial']['elec_mwh'] / r['residential']['total_pop']
        us_res_elec = 3.64
        us_com_elec = 3.29
        us_ind_elec = 2.62
        values_elec = [
            i_res_elec, us_res_elec, i_com_elec, us_com_elec, i_ind_elec,
            us_ind_elec
        ]
        canvas_elec, axes_elec, mark_elec = toyplot.bars(
            values_elec,
            width=550,
            height=350,
            color=colors,
            label=f'{geo} Electricity Consumption Per Capita',
            ylabel='MWh')
        axes_elec.x.ticks.locator = toyplot.locator.Explicit(labels=labels)
        h_elec = toyplot.html.tostring(canvas_elec)
        return h_elec

    elif resource == 'Gas':
        i_res_gas = r['residential']['gas_mcf'] / r['residential']['total_pop']
        i_com_gas = r['commercial']['gas_mcf'] / r['residential']['total_pop']
        i_ind_gas = r['industrial']['gas_mcf'] / r['residential']['total_pop']
        us_res_gas = 15.42
        us_com_gas = 7.96
        us_ind_gas = 19.8

        values_gas = [
            i_res_gas, us_res_gas, i_com_gas, us_com_gas, i_ind_gas, us_ind_gas
        ]
        canvas_gas, axes_gas, mark_gas = toyplot.bars(
            values_gas,
            width=550,
            height=350,
            color=colors,
            label=f'{geo} Natural Gas Consumption Per Capita',
            ylabel='MCF')
        axes_gas.x.ticks.locator = toyplot.locator.Explicit(labels=labels)
        h_gas = toyplot.html.tostring(canvas_gas)
        return h_gas