Example #1
0
 def _update_plot(self, axis, view):
     sns.tsplot(view.data,
                view.xdata,
                ax=axis,
                condition=view.label,
                zorder=self.zorder,
                **self.style)
Example #2
0
def plot_timeseries(experiment, kinematic=None):
    ensemble = experiment.observations.kinematics
    #    traj_numbers = [int(i) for i in ensemble.index.get_level_values('trajectory_num').unique()]
    data_dict = {}

    # for each kinematic, slice out each trajectory, append to data_dict
    if kinematic is None:
        col_list = list(ensemble.columns.values)
        col_list.remove('tsi')
        col_list.remove('trajectory_num')
    else:
        col_list = []
        for dim in ['x', 'y', 'z']:
            col_list.append(kinematic + '_' + dim)

    for col in col_list:
        data = []
        col_data = ensemble[['tsi', 'trajectory_num', col]]  # this all trajectories

        #        # store each trajectory to data
        #        for i in traj_numbers:
        #            df = col_data.xs(i, level='trajectory_num')
        #            data.append(df)
        #
        #        data_dict[col] = data  # every key linked to list of lists
        data_dict[col] = col_data

    #### file naming and directory selection
    fileappend, path, agent = get_agent_info(experiment.agent)

    titlebase = "{agent} {kinematic} timeseries".format(agent=agent, kinematic="{kinematic}")
    numbers = " (n = {})".format(ensemble['trajectory_num'].max())

    # k is kinematic v is a list of trajectories
    for k, v in data_dict.iteritems():
        # print k
        # print v
        print "plotting {}".format(k)
        plt.figure()
        #        for i, trial in enumerate(v):
        #            plt.plot(trial.index, trial, alpha=0.3)
        # print v
        sns.tsplot(data=v, times='tsi', value=k, err_style=None)  # "unit_traces")  FIXME
        format_title = titlebase.format(kinematic=k)
        plt.suptitle(format_title + numbers, fontsize=14)
        plt.xlabel("Timestep index")
        plt.ylabel("Value")
        plt.legend()  # FIXME remove after debugging
        plt.savefig(os.path.join(path, format_title + fileappend + FIG_FORMAT))
        plt.show()
Example #3
0
 def _update_plot(self, axis, view):
     kwargs = self.style[self.cyclic_index]
     label = view.label if self.overlaid >= 1 else ''
     if label:
         kwargs['condition'] = label
     sns.tsplot(view.data, view.xdata, ax=axis, zorder=self.zorder, **kwargs)
Example #4
0
 def _update_plot(self, axis, view):
     sns.tsplot(view.data, view.xdata, ax=axis, condition=view.label,
                zorder=self.zorder, **self.style)
Example #5
0
 def init_artists(self, ax, plot_data, plot_kwargs):
     return {'axis': sns.tsplot(*plot_data, ax=ax, **plot_kwargs)}
Example #6
0
 def init_artists(self, ax, plot_data, plot_kwargs):
     return {'axis': sns.tsplot(*plot_data, ax=ax, **plot_kwargs)}
Example #7
0
def forced_swim_timecourse(
    df,
    bp_style=True,
    colorset=QUALITATIVE_COLORSET,
    datacolumn_label="Immobility Ratio",
    legend_loc="best",
    plotstyle="tsplot",
    rename_treatments={},
    time_label="interval [1 min]",
    save_as=False,
):
    """Plot timecourse of forced swim measurements.

	Parameters
	----------

	df : {pandas.Dataframe, string}
	Pandas Dataframe containing the experimental data, or path pointing to a csv containing such data.

	bp_style : bool, optional
	Whether to apply the default behaviopy style.

	datacolumn_label : string, optional
	A column name from df, the values in which column give the data to plot.

	legend_loc : string, optional
	Where to place the legend on the figure.

	plotstyle : {"pointplot", "tsplot"}
	Dictionary with strings as keys and values used to map treatment names onto new stings.

	rename_treatments : dict, optional
	Dictionary with strings as keys and values used to map treatment names onto new stings.

	time_label : dict, optional
	A column name from df, the values in which column give the time pointd of the data.
	"""

    try:
        if isinstance(df, basestring):
            df = path.abspath(path.expanduser(df))
            df = pd.read_csv(df)
    except NameError:
        if isinstance(df, str):
            df = path.abspath(path.expanduser(df))
            df = pd.read_csv(df)

    for key in rename_treatments:
        df.loc[df["Treatment"] == key, "Treatment"] = rename_treatments[key]
    df = control_first_reordering(df, "Treatment")
    if bp_style:
        sns.set_style("white", {'legend.frameon': True})
        plt.style.use(u'seaborn-darkgrid')
        plt.style.use(u'ggplot')
    if plotstyle == "tsplot":
        myplot = sns.tsplot(time=time_label,
                            value=datacolumn_label,
                            condition="Treatment",
                            unit="Identifier",
                            data=df,
                            err_style="unit_traces",
                            color=sns.color_palette(colorset))
        myplot.set_xticks(list(set(df[time_label])))
    elif plotstyle == "pointplot":
        sns.pointplot(x=time_label,
                      y=datacolumn_label,
                      hue="Treatment",
                      data=df,
                      palette=sns.color_palette(colorset),
                      legend_out=False,
                      dodge=0.1)
    plt.legend(loc=legend_loc, frameon=True)

    if save_as:
        plt.savefig(path.abspath(path.expanduser(save_as)),
                    bbox_inches='tight')