def get_max_move_size(prev, next, ids):
    group_info = data.read_group_info('Fri').set_index('group_id')
    # places = pd.DataFrame(data={'prev': prev, 'next': next}).dropna().astype('int64')
    places = pd.DataFrame(data={'prev': prev, 'next': next}, index=ids)
    # drop any rows with 0 for the place id, as we can't plot that.
    places = places.loc[(places != 0).all(axis=1)]
    places['size'] = group_info['size']
    p2 = places.groupby(['next', 'prev']).sum().reset_index().sort_values('size')
    # remove the small slices
    # p2 = p2[p2['size'] >= 8]
    max_size = p2['size'].max()
    return max_size
示例#2
0
def get_max_move_size(prev, next, ids):
    group_info = data.read_group_info('Fri').set_index('group_id')
    # places = pd.DataFrame(data={'prev': prev, 'next': next}).dropna().astype('int64')
    places = pd.DataFrame(data={'prev': prev, 'next': next}, index=ids)
    # drop any rows with 0 for the place id, as we can't plot that.
    places = places.loc[(places != 0).all(axis=1)]
    places['size'] = group_info['size']
    p2 = places.groupby(['next', 'prev']).sum().reset_index().sort_values('size')
    # remove the small slices
    # p2 = p2[p2['size'] >= 8]
    max_size = p2['size'].max()
    return max_size
def plot_next_place(prev, next, ids, ax=None, max_size=None):
    if ax is None:
        fig, ax = plt.subplots()

    kp = data.read_key_points().set_index('place_id')
    group_info = data.read_group_info('Fri').set_index('group_id')

    # places = pd.DataFrame(data={'prev': prev, 'next': next}).dropna().astype('int64')
    places = pd.DataFrame(data={'prev': prev, 'next': next}, index=ids)
    # drop any rows with 0 for the place id, as we can't plot that.
    places = places.loc[(places != 0).all(axis=1)]
    places['size'] = group_info['size']
    p2 = places.groupby(['next',
                         'prev']).sum().reset_index().sort_values('size')
    # remove the small slices
    # p2 = p2[p2['size'] >= 8]
    if max_size is None:
        max_size = p2['size'].max()
        # print(max_size)

    im = data.read_image('Grey')
    ax.imshow(im, extent=[0, 100, 0, 100])

    cmap = plt.get_cmap('plasma')
    for i, row in enumerate(p2.itertuples()):
        # index_amt = i / (len(p2) - 1)
        size_amt = row.size / max_size
        prev_xy = kp.loc[row.prev, ['X', 'Y']].values
        next_xy = kp.loc[row.next, ['X', 'Y']].values
        arrowprops = {
            'arrowstyle': 'simple',
            'mutation_scale': 50 * size_amt,
            'alpha': 0.2 + 0.8 * size_amt,
            'lw': 0,
            'color': cmap(0.5 * size_amt),
            'connectionstyle': "arc3,rad=-0.1"
        }
        ax.annotate('', xy=next_xy, xytext=prev_xy, arrowprops=arrowprops)
    ax.xaxis.set_ticks([])
    ax.yaxis.set_ticks([])
def plot_next_place(prev, next, ids, ax=None, max_size=None):
    if ax is None:
        fig, ax = plt.subplots()

    kp = data.read_key_points().set_index('place_id')
    group_info = data.read_group_info('Fri').set_index('group_id')

    # places = pd.DataFrame(data={'prev': prev, 'next': next}).dropna().astype('int64')
    places = pd.DataFrame(data={'prev': prev, 'next': next}, index=ids)
    # drop any rows with 0 for the place id, as we can't plot that.
    places = places.loc[(places != 0).all(axis=1)]
    places['size'] = group_info['size']
    p2 = places.groupby(['next', 'prev']).sum().reset_index().sort_values('size')
    # remove the small slices
    # p2 = p2[p2['size'] >= 8]
    if max_size is None:
        max_size = p2['size'].max()
        # print(max_size)

    im = data.read_image('Grey')
    ax.imshow(im, extent=[0, 100, 0, 100])

    cmap = plt.get_cmap('plasma')
    for i, row in enumerate(p2.itertuples()):
        # index_amt = i / (len(p2) - 1)
        size_amt = row.size / max_size
        prev_xy = kp.loc[row.prev, ['X', 'Y']].values
        next_xy = kp.loc[row.next, ['X', 'Y']].values
        arrowprops = {'arrowstyle': 'simple',
                      'mutation_scale': 50 * size_amt,
                      'alpha': 0.2 + 0.8 * size_amt,
                      'lw': 0,
                      'color': cmap(0.5 * size_amt),
                      'connectionstyle': "arc3,rad=-0.1"}
        ax.annotate('', xy=next_xy, xytext=prev_xy, arrowprops=arrowprops)
    ax.xaxis.set_ticks([])
    ax.yaxis.set_ticks([])
示例#5
0
import data
import numpy as np
import matplotlib.pyplot as plt

kp = data.read_visited_key_points('Fri', extra=['X', 'Y'], grouped=True)
groups = data.read_group_info('Fri')

# the group that visited the least things
shortest_group = kp.groupby('group_id').size().argmin()
# the group that visited the most things
longest_group = kp.groupby('group_id').size().argmax()
# the largest group
largest_group = groups['size'].argmax()

df = kp[kp['group_id'] == longest_group]

im = data.read_image('grey')
plt.imshow(im, extent=[0, 100, 0, 100])

cmap = plt.get_cmap('rainbow')
for i in range(len(df) - 1):
    amt = i / (len(df) - 2)
    color = np.array(cmap(amt))
    color[:-1] *= 0.8
    prev = df.iloc[i]
    next = df.iloc[i + 1]
    # tdiff = next.Timestamp - prev.Timestamp
    # size = 0.001 * (tdiff / np.timedelta64(1, 's'))
    # text = '{} -> {}'.format(prev.place_id, next.place_id)
    arrowprops = {
        'arrowstyle': 'simple',