def plot_colored_cartesian_spagetti(dataset, axis='xy', xlim=(-0.2, .2), ylim=(-0.75, .25), zlim=(0, 0.3), keys=None, keys_to_highlight=[], show_saccades=False, colormap='jet', color_attribute='speed', norm=(0,0.5), artists=None, save_figure_path=''):
    keys = get_keys(dataset)
    print 'plotting spagetti, axis: ', axis
    print 'number of keys: ', len(keys)
    if len(keys) < 1:
        print 'No data'
        return
        
    fig = plt.figure()
    ax = fig.add_subplot(111)

    if axis=='xy': # xy plane
        ax.set_ylim(ylim[0], ylim[1])
        ax.set_xlim(xlim[0], xlim[1])
        ax.set_autoscale_on(True)
        ax.set_aspect('equal')
        axes=[0,1]
        fap.cartesian_spagetti(ax, dataset, keys=keys, nkeys=300, start_key=0, axes=axes, show_saccades=show_saccades, keys_to_highlight=[], colormap=colormap, color_attribute=color_attribute, norm=norm, show_start=False)
        
    if axis=='yz': # yz plane
        ax.set_ylim(zlim[0], zlim[1])
        ax.set_xlim(ylim[0], ylim[1])
        ax.set_autoscale_on(True)
        ax.set_aspect('equal')
        axes=[1,2]
        fap.cartesian_spagetti(ax, dataset, keys=keys, nkeys=300, start_key=0, axes=axes, show_saccades=show_saccades, keys_to_highlight=[], colormap=colormap, color_attribute=color_attribute, norm=norm, show_start=False)
        
    if artists is not None:
        for artist in artists:
            ax.add_artist(artist)

    #prep_cartesian_spagetti_for_saving(ax)
    xticks = np.linspace(xlim[0], xlim[1], 3, endpoint=True).tolist()
    yticks = np.linspace(ylim[0], ylim[1], 5, endpoint=True).tolist()
    zticks = np.linspace(zlim[0], zlim[1], 3, endpoint=True).tolist()
    
    if axis=='xy':
        fpl.adjust_spines(ax, ['left', 'bottom'], xticks=xticks, yticks=yticks)
        ax.set_xlabel('x axis, m')
        ax.set_ylabel('y axis, m')
        ax.set_title('xy plot, color=speed from 0-0.5 m/s')

    if axis=='yz':
        fpl.adjust_spines(ax, ['left', 'bottom'], xticks=yticks, yticks=zticks)
        ax.set_xlabel('y axis, m')
        ax.set_ylabel('z axis, m')
        ax.set_title('yz plot, color=speed from 0-0.5 m/s')

    fig.set_size_inches(8,8)
    figname = save_figure_path + 'spagetti_' + axis + '.pdf'
    fig.savefig(figname, format='pdf')

    return ax
def plot_activity_histogram(dataset, save_figure_path=""):
    keys = get_keys(dataset)
    print "number of keys: ", len(keys)
    if len(keys) < 1:
        print "No data"
        return

    local_time = []
    for i, key in enumerate(keys):
        trajec = dataset.trajecs[key]
        local_time.append(trajec.timestamp_local_float)
    local_time = np.array(local_time)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    nbins = 24  # note: if show_smoothed=True with default butter filter, nbins needs to be > ~15
    bins = np.linspace(0, 24, nbins)

    fpl.histogram(
        ax,
        [local_time],
        bins=bins,
        bin_width_ratio=0.8,
        colors=["green"],
        edgecolor="none",
        bar_alpha=1,
        curve_fill_alpha=0.4,
        curve_line_alpha=0,
        curve_butter_filter=[3, 0.3],
        return_vals=False,
        show_smoothed=True,
        normed=True,
        normed_occurences=False,
        bootstrap_std=False,
        exponential_histogram=False,
    )

    xticks = np.linspace(bins[0], bins[-1], 5, endpoint=True)
    fpl.adjust_spines(ax, ["left", "bottom"], xticks=xticks)
    ax.set_xlabel("Time of day, hours")
    ax.set_ylabel("Occurences, normalized")
    ax.set_title("Activity, as measured by number of trajectories")

    fig.set_size_inches(8, 8)
    figname = save_figure_path + "activity_histogram" + ".pdf"
    fig.savefig(figname, format="pdf")