def __init__(self):
        vals = getDefaultPosition()

        x_sc = LinearScale(min=0, max=4)
        y_sc = LinearScale(min=0, max=8)
        y_sc.reverse = True

        x_sc.allow_padding = False
        y_sc.allow_padding = False

        # -1 are the empty squares (not in output from network)
        col_sc = ColorScale(min=-1, max=1, colors=['red', 'white', 'black'])

        x_ax = Axis(label='X', scale=x_sc)
        y_ax = Axis(label='Y', scale=y_sc, orientation='vertical')

        bg = plt.gridheatmap(vals,
                             scales={
                                 'column': x_sc,
                                 'row': y_sc,
                                 'color': col_sc
                             })

        self.board = bg

        fig = Figure(marks=[bg], axes=[x_ax, y_ax])
        fig.min_aspect_ratio = 0.63  # Idfk why this makes it have an aspect ratio around 0.5 but w/e
        fig.max_aspect_ratio = 0.63

        self.fig = fig
    def __init__(self):
        # Setup & Axis stuff...
        x_sc = LinearScale(min=0, max=8)
        y_sc = LinearScale(min=0, max=8)

        x_ax = Axis(label='X', scale=x_sc)
        y_ax = Axis(label='Y', scale=y_sc, orientation='vertical')
        y_sc.reverse = True

        col_sc = ColorScale(min=-1, max=1, colors=['white', 'blue', 'red'])
        bg = plt.gridheatmap(np.zeros((16, 16)),
                             scales={
                                 'column': x_sc,
                                 'row': y_sc,
                                 'color': col_sc
                             })
        bg.row = np.arange(16) / 2
        bg.column = np.arange(16) / 2

        self.board = bg

        fig = Figure(marks=[bg], axes=[x_ax, y_ax])

        # Force square.
        fig.min_aspect_ratio = 1
        fig.max_aspect_ratio = 1

        # Give random data
        self.update(np.random.random((8, 4, 4)))

        self.fig = fig
    def __init__(self, canInteract=True):

        # Setup & Axis stuff...
        x_sc = LinearScale(min=0, max=8)
        y_sc = LinearScale(min=0, max=8)
        y_sc.reverse = True

        x_ax = Axis(label='X', scale=x_sc)
        y_ax = Axis(label='Y', scale=y_sc, orientation='vertical')

        # Display starting position for checkers game.

        # Colour checkerboard... Extra stuff for alignment to grid.
        vals = np.zeros((8, 8))
        vals[::2, ::2] = -1
        vals[1::2, 1::2] = -1

        col_sc = ColorScale(colors=['white', 'lightgray'])
        bg = plt.gridheatmap(vals,
                             scales={
                                 'column': x_sc,
                                 'row': y_sc,
                                 'color': col_sc
                             })
        bg.row = np.arange(8)
        bg.column = np.arange(8)

        self.bg = bg

        # Foreground...
        # colors of pieces
        col_sc = ColorScale(colors=['firebrick', 'black'])

        # Create empty scatter grid.
        fg = Scatter(x=[], y=[])
        fg.scales = {'x': x_sc, 'y': y_sc, 'color': col_sc}
        fg.color = []
        fg.default_size = 550
        fg.enable_move = canInteract
        print(fg.drag_size)
        fg.drag_size = 0.1
        print(fg.drag_size)

        self.fg = fg

        fig = Figure(marks=[bg, fg], axes=[x_ax, y_ax])

        # Force square.
        fig.min_aspect_ratio = 1
        fig.max_aspect_ratio = 1

        # display(fig)
        self.fig = fig
示例#4
0
文件: vgan.py 项目: cyhsu/vgan
def sidebarCalendarHeatmap(PI):
    dataframe = pd.read_json('./Data/PIcontribution/{}.json'.format(PI))
    figs, years = [], np.unique(dataframe.index.year)

    #-- Calendar Heatmap by bqplot.
    for year in years[:
                      -1]:  #-- years[:-1] is because the end year + 1 is the upper bound.
        data = dataframe[str(year)]
        data = pd.DataFrame({
            'data': data.trajectory,
            'fill': 1,
            'day': data.index.dayofweek,
            'week': data.index.isocalendar().week
        })
        data.loc[(data.index.month == 1) & (data.week > 50), 'week'] = 0
        data.loc[(data.index.month == 12) & (data.week < 10),
                 'week'] = data.week.max() + 1

        fill_data = data.pivot('day', 'week', 'fill').values[::-1]
        fill_data = np.ma.masked_where(np.isnan(fill_data), fill_data)

        plot_data = data.pivot('day', 'week', 'data').values  #[::-1]
        plot_data = np.ma.masked_where(np.isnan(plot_data), plot_data)

        monthlabels = np.arange(data.index[0],
                                data.index[-1] + np.timedelta64(1, 'D'),
                                dtype='datetime64[D]')[::7]
        daylabels = list(['Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat', 'Sun'])

        Layout = widgets.Layout(width='auto', height='200px')
        #Layout = widgets.Layout(width='100%',height='200px')
        fig = bplt.figure(
            layout=Layout,
            fig_margin=dict(top=20, bottom=20, left=60, right=40),
            padding_y=0,
        )

        xmin, xmax = np.datetime64('{:04d}-01-01'.format(year)), np.datetime64(
            '{:04d}-12-31'.format(year))
        bplt.scales(
            scales={
                'x': DateScale(
                    min=xmin,
                    max=xmax,
                    offset={'value': 1},
                ),
                'y': OrdinalScale(reverse=True)
            })
        bplt.gridheatmap(fill_data,
                         row=daylabels,
                         column=monthlabels,
                         stroke='white',
                         opacity=0.3,
                         scales={'color': ColorScale(scheme='Grays')},
                         axes_options={'color': {
                             'visible': False
                         }})

        grid_map = bplt.gridheatmap(
            plot_data,
            row=daylabels,
            column=monthlabels,
            opacity=0.7,
            stroke='white',
            scales={'color': ColorScale(colors=['whitesmoke', 'darkgreen'])},
            axes_options={
                'row': {
                    'label_offset': '3em',
                    'label': str(year),
                    'num_ticks': 4,
                    'grid_lines': 'none'
                },
                'column': {
                    'num_ticks': 5,
                    'grid_lines': 'none'
                },
                'color': {
                    'visible': False
                }
            })
        figs.append(fig)
    return widgets.VBox(figs,
                        layout=widgets.Layout(
                            align_items='center',
                            justify_content='center',
                            margin='2%',
                        ))