Exemplo n.º 1
0
def test_axes_fill_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.fill(b)
    assert_canvas_matches(canvas, "axes-fill-boundaries-masked-nan")
Exemplo n.º 2
0
def test_axes_fill_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.fill(b)
    assert_canvas_matches(canvas, "axes-fill-boundaries-masked-nan")
Exemplo n.º 3
0
def test_axes_fill_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.fill(x, y, baseline="stacked")
    assert_canvas_matches(canvas, "axes-fill-magnitudes-masked-nan")
Exemplo n.º 4
0
def test_axes_fill_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.fill(x, y, baseline="stacked")
    assert_canvas_matches(canvas, "axes-fill-magnitudes-masked-nan")
Exemplo n.º 5
0
                sample_sets=samples,
                windows=np.linspace(
                    start=0, 
                    stop=self.tree_sequence.sequence_length, 
                    num=round(self.tree_sequence.sequence_length / window_size)
                )
            )
            rep_values.append(values)
        
        # get mean and std
        means = np.array(rep_values).mean(axis=0)
        stds = np.array(rep_values).mean(axis=0)        

        # draw canvas...
        canvas, axes, mark  = toyplot.fill(
            means, height=300, width=500, opacity=0.5, margin=(60, 50, 50, 80)
        )

        # style axes
        axes.x.ticks.show = True
        axes.x.ticks.locator = toyplot.locator.Extended(only_inside=True)
        axes.y.ticks.labels.angle = -90
        axes.y.ticks.show = True
        axes.y.ticks.locator = toyplot.locator.Extended(only_inside=True, count=5)        
        axes.label.offset = 20
        axes.label.text = f"{stat} in {int(window_size / 1000)}kb windows"
        return canvas, axes, mark



Exemplo n.º 6
0
                              stop=self.tree_sequence.sequence_length,
                              num=round(self.tree_sequence.sequence_length /
                                        window_size)))
            rep_values.append(values)

        # get mean and std
        means = np.array(rep_values).mean(axis=0)
        stds = np.array(rep_values).mean(axis=0)

        # draw canvas...
        style = {"fill": str(color)}

        canvas, axes, mark = toyplot.fill(
            means,
            height=300,
            width=500,
            opacity=0.5,
            margin=(60, 50, 50, 80),
            style=style,
        )

        # style axes
        axes.x.ticks.show = True
        axes.x.ticks.locator = toyplot.locator.Extended(only_inside=True)
        axes.y.ticks.labels.angle = -90
        axes.y.ticks.show = True
        axes.y.ticks.locator = toyplot.locator.Extended(only_inside=True,
                                                        count=5)
        axes.label.offset = 20
        axes.label.text = f"{stat} in {int(window_size / 1000)}kb windows"
        return canvas, axes, mark
Exemplo n.º 7
0
def ResourceMixPlotter(state):
    cp = toyplot.color.Palette()
    alt_cp = toyplot.color.brewer.palette("Accent")
    cpdict = {
        'Coal': alt_cp[7],
        'Natural Gas': cp[6],
        'Nuclear': cp[4],
        'Geothermal': cp[1],
        'Biomass': cp[3],
        'Wind': cp[0],
        'Solar': cp[5],
        'Hydro': cp[2],
        'Other': cp[7]
    }

    resources = {
        'Coal': 'COW',
        'Petroleum': 'PEL',
        'Natural Gas': 'NG',
        'Nuclear': 'NUC',
        'Hydro': 'HYC',
        'Geothermal': 'GEO',
        'Biomass': 'WWW',
        'Wind': 'WND',
        'Small-Scale PV': 'DPV',
        'PV': 'SPV',
        'CSP': 'STH',
        'Hydro PS': 'HPS',
        'Other Bio': 'WAS',
        'Other': 'OTH',
        'Other Gas': 'OOG',
        'Petroleum Coke': 'PC'
    }
    state_abrev = us_state_abbrev[state]
    s_list = []
    for key, value in resources.items():
        j_ = requestmaker(api_url=f'ELEC.GEN.{value}-{state_abrev}-99.A',
                          source='EIA')
        if 'series' in j_:
            r = j_['series'][0]['data']
            s_ = pd.Series([i[1] for i in r], index=[i[0] for i in r])
            s_.name = key
            s_list.append(s_)
    df = pd.concat(s_list, axis=1)[-10:]
    otherlist = [
        'Petroleum Coke', 'Other Gas', 'Other Bio', 'Hydro PS', 'Petroleum',
        'Small-Scale PV', 'PV', 'CSP'
    ]
    for l in otherlist:
        if l not in df.columns:
            df[l] = 0
    for l in ['Hydro']:
        if l not in df.columns:
            df[l] = 0

    df['Other'] = df['Other'] + df['Other Gas'] + df['Petroleum Coke'] + df[
        'Other Bio'] + df['Petroleum']
    df['Hydro'] = df['Hydro'] + df['Hydro PS']
    df['Solar'] = df['Small-Scale PV'] + df['PV'] + df['CSP']
    df.drop(axis='columns', labels=otherlist, inplace=True)
    df.dropna(how='all', inplace=True)
    df.fillna(0, inplace=True)
    df = df / 100
    df.sort_values(by='2017', axis='columns', inplace=True, ascending=False)
    resourcelist = df.columns

    resourcecolorlist = [cpdict[i] for i in resourcelist]

    dfout = df.values
    canvas, axes, mark = toyplot.fill(dfout,
                                      width=550,
                                      height=350,
                                      color=resourcecolorlist,
                                      baseline='stacked',
                                      margin=(40, 95, 40, 45),
                                      label=f'{state} Resource Generation Mix',
                                      ylabel='GWh')

    legendlist = []
    count = 0
    for i in resourcelist:
        l = (i, mark.markers[count])
        legendlist.append(l)
        count += 1
    legendlist = list(reversed(legendlist))
    canvas.legend(legendlist, corner=("right", 50, 40, 200))
    axes.x.ticks.locator = toyplot.locator.Explicit(labels=df.index)
    h = toyplot.html.tostring(canvas)
    return h