def plot_ci_for_ms(path, figname, vals, figsize=(6,4)):

    figname = os.path.splitext(figname)[0]

    NAMES = {'TH>trpA1 head':'TH>trpA1 (head)',
              'TH>trpA1 thorax':'TH>trpA1 (thorax)',
              'TH head':'TH (head)',
              'TH thorax':'TH (thorax)',
              'trpA1 head':'trpA1 (head)',
              'trpA1 thorax':'trpA1 (thorax)',
              'controls head':'controls (head)',
              'controls thorax':'controls (thorax)',
    }
    COLORS = {'TH>trpA1 head':flymad_plot.RED,
              'TH>trpA1 thorax':flymad_plot.ORANGE,
              'TH head':flymad_plot.GREEN,
              'TH thorax':flymad_plot.BLUE,
              'trpA1 head':flymad_plot.GREEN,
              'trpA1 thorax':flymad_plot.BLUE,
              'controls head':flymad_plot.GREEN,
              'controls thorax':flymad_plot.BLUE,
    }

    ORDER = ['TH>trpA1 head',
              'TH>trpA1 thorax',
              'TH head',
              'TH thorax',
              'trpA1 head',
              'trpA1 thorax',
              'controls head',
              'controls thorax',
    ]


    figure_title = "THGAL4 %s cumulative incidence" % figname
    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(1,1,1)

    for gt in sorted(vals, cmp=lambda a,b: cmp(ORDER.index(a), ORDER.index(b))):
        ax.plot(vals[gt]['x'],vals[gt]['y'],
                lw=2,clip_on=False,
                color=COLORS[gt],label=NAMES[gt])

    spine_placer(ax, location='left,bottom' )
    ax.legend()

    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Cumulative incidence (%)')
    ax.set_ylim([0,100])
    ax.set_xlim([0,20])

    flymad_plot.retick_relabel_axis(ax, [0,10,20], [0,100])

    fig.savefig(flymad_plot.get_plotpath(path,"thgal4_ci_%s.png" % figname), bbox_inches='tight')
    fig.savefig(flymad_plot.get_plotpath(path,"thgal4_ci_%s.svg" % figname), bbox_inches='tight')
def plot_all_data(path, data, arena, note, laser='350iru'):

    ORDER = ["50660trp","50660","wtrp"]
    COLORS = {"50660trp":flymad_plot.RED,"50660":flymad_plot.BLACK,"wtrp":flymad_plot.BLUE}

    datasets = {}

    figure_title = "Moonwalker"
    fig = plt.figure(figure_title, figsize=TS_FIGSIZE)
    ax = fig.add_subplot(1,1,1)

    for gt in data:
        gtdf = data[gt][laser][gt]
        datasets[gt] = dict(xaxis=gtdf['mean']['t'].values,
                            value=gtdf['mean']['Vfwd'].values,
                            std=gtdf['std']['Vfwd'].values,
                            n=gtdf['n']['Vfwd'].values,
                            order=ORDER.index(gt),
                            label=flymad_analysis.human_label(gt),
                            color=COLORS[gt],
                            N=len(gtdf['df']['obj_id'].unique()),
                            df=gtdf['df'],
        )

    l, axs, figs = flymad_plot.plot_timeseries_with_activation(ax,
                        targetbetween=dict(xaxis=data['50660trp'][laser]['50660trp']['first']['t'].values,
                                           where=data['50660trp'][laser]['50660trp']['first']['laser_state'].values>0),
                        downsample=5,
                        sem=True,
                        note="%s\n" % (note,),
                        individual={k:{'groupby':('obj_id','trial'),'xaxis':'t','yaxis':'Vfwd'} for k in datasets},
                        individual_title=figure_title + ' Individual Traces',
                        **datasets
    )

    ax.axhline(color='k', linestyle='--',alpha=0.8)
    ax.set_ylim(YLIM)
    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Forward velocity (%s/s)' % arena.unit)
    ax.set_xlim(XLIM)

    flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

    fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_simple.png"), bbox_inches='tight')
    fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_simple.svg"), bbox_inches='tight')

    for efigname, efig in figs.iteritems():
        efig.savefig(flymad_plot.get_plotpath(path,"moonwalker_simple_individual_%s.png" % efigname), bbox_inches='tight')
Beispiel #3
0
def plot_data(path, data):
    ci_html_buf = ''

    for exp_name in data:
        gts = data[exp_name].keys()

        laser = '130ht'
        gts_string = 'vs'.join(gts)
        figname = laser + '_' + gts_string

        fig = plt.figure("Song (%s)" % figname, figsize=(10, 6))
        ax = fig.add_subplot(1, 1, 1)

        datasets = {}
        for gt in gts:

            if flymad_analysis.genotype_is_exp(gt):
                color = flymad_plot.RED
                order = 1
            elif flymad_analysis.genotype_is_ctrl(gt):
                color = flymad_plot.BLACK
                order = 2
            elif flymad_analysis.genotype_is_trp_ctrl(gt):
                order = 3
                color = flymad_plot.BLUE
            else:
                color = 'cyan'
                order = 0

            gtdf = data[exp_name][gt]
            datasets[gt] = dict(xaxis=gtdf['mean']['t'].values,
                                value=gtdf['mean']['zx'].values,
                                std=gtdf['std']['zx'].values,
                                n=gtdf['n']['zx'].values,
                                order=order,
                                df=gtdf,
                                label=flymad_analysis.human_label(gt),
                                color=color,
                                N=len(gtdf['df']['obj_id'].unique()))

        pvalue_buf = ''

        for gt in datasets:
            label = flymad_analysis.human_label(gt)
            if '>' not in label:
                continue

            # OK, this is a Gal4 + UAS - do head vs thorax stats
            gtdf = data[exp_name][gt]['df']
            ci_data = do_cum_incidence(gtdf, label)
            ci_html_buf += ci_data['buf']

            ax_cum = ci_data['ax']
            spine_placer(ax_cum, location='left,bottom')

            ax_cum.set_ylabel('Fraction extending wing (%)')
            ax_cum.set_xlabel('Time (s)')

            note = '%s\n%s\np-value: %.3g\n%d flies\nn=%d, %d' % (
                label, madplot.p2stars(ci_data['p_value']), ci_data['p_value'],
                len(gtdf['obj_id'].unique()), ci_data['n_head'],
                ci_data['n_thorax'])
            ax_cum.text(
                0,
                1,  #top left
                note,
                fontsize=10,
                horizontalalignment='left',
                verticalalignment='top',
                transform=ax_cum.transAxes,
                zorder=0)

            ci_data['fig'].savefig(flymad_plot.get_plotpath(
                path, "song_cum_inc_%s.png" % figname),
                                   bbox_inches='tight')
            ci_data['fig'].savefig(flymad_plot.get_plotpath(
                path, "song_cum_inc_%s.svg" % figname),
                                   bbox_inches='tight')


#            for i in range(len(head_times)):
#                head_values = gtdf[gtdf['t']==head_times[i]]
#                thorax_values = gtdf[gtdf['t']==thorax_times[i]]
#                test1 = head_values['zx'].values
#                test2 = thorax_values['zx'].values
#                hval, pval = kruskal(test1, test2)
#                pvalue_buf += 'Pulse %d: Head vs thorax WEI p-value: %.3g (n=%d, %d)\n'%(
#                    i+1, pval, len(test1), len(test2) )

#all experiments used identical activation times
        headtargetbetween = dict(
            xaxis=data['pIP10']['wtrpmyc']['first']['t'].values,
            where=data['pIP10']['wtrpmyc']['first']['ttm'].values > 0)
        thoraxtargetbetween = dict(
            xaxis=data['pIP10']['wtrpmyc']['first']['t'].values,
            where=data['pIP10']['wtrpmyc']['first']['ttm'].values < 0)

        flymad_plot.plot_timeseries_with_activation(
            ax,
            targetbetween=[headtargetbetween, thoraxtargetbetween],
            sem=True,
            note=pvalue_buf,
            **datasets)

        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Wing extension index')
        ax.set_ylim([-0.05, 0.4] if gts_string ==
                    "40347vswtrpmycvs40347trpmyc" else [-0.05, 1.0])
        ax.set_xlim([-10, 180])

        flymad_plot.retick_relabel_axis(
            ax, [0, 60, 120, 180], [0, 0.2, 0.4]
            if gts_string == "40347vswtrpmycvs40347trpmyc" else [0, 0.5, 1])

        fig.savefig(flymad_plot.get_plotpath(path, "song_%s.png" % figname),
                    bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path, "song_%s.svg" % figname),
                    bbox_inches='tight')

    with open(flymad_plot.get_plotpath(path, "song_cum_in.html"),
              mode='w') as fd:
        fd.write(ci_html_buf)
Beispiel #4
0
def plot_ci_for_ms(path, figname, vals, figsize=(6, 4)):

    figname = os.path.splitext(figname)[0]

    NAMES = {
        'TH>trpA1 head': 'TH>trpA1 (head)',
        'TH>trpA1 thorax': 'TH>trpA1 (thorax)',
        'TH head': 'TH (head)',
        'TH thorax': 'TH (thorax)',
        'trpA1 head': 'trpA1 (head)',
        'trpA1 thorax': 'trpA1 (thorax)',
        'controls head': 'controls (head)',
        'controls thorax': 'controls (thorax)',
    }
    COLORS = {
        'TH>trpA1 head': flymad_plot.RED,
        'TH>trpA1 thorax': flymad_plot.ORANGE,
        'TH head': flymad_plot.GREEN,
        'TH thorax': flymad_plot.BLUE,
        'trpA1 head': flymad_plot.GREEN,
        'trpA1 thorax': flymad_plot.BLUE,
        'controls head': flymad_plot.GREEN,
        'controls thorax': flymad_plot.BLUE,
    }

    ORDER = [
        'TH>trpA1 head',
        'TH>trpA1 thorax',
        'TH head',
        'TH thorax',
        'trpA1 head',
        'trpA1 thorax',
        'controls head',
        'controls thorax',
    ]

    figure_title = "THGAL4 %s cumulative incidence" % figname
    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(1, 1, 1)

    for gt in sorted(vals,
                     cmp=lambda a, b: cmp(ORDER.index(a), ORDER.index(b))):
        ax.plot(vals[gt]['x'],
                vals[gt]['y'],
                lw=2,
                clip_on=False,
                color=COLORS[gt],
                label=NAMES[gt])

    spine_placer(ax, location='left,bottom')
    ax.legend()

    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Cumulative incidence (%)')
    ax.set_ylim([0, 100])
    ax.set_xlim([0, 20])

    flymad_plot.retick_relabel_axis(ax, [0, 10, 20], [0, 100])

    fig.savefig(flymad_plot.get_plotpath(path, "thgal4_ci_%s.png" % figname),
                bbox_inches='tight')
    fig.savefig(flymad_plot.get_plotpath(path, "thgal4_ci_%s.svg" % figname),
                bbox_inches='tight')
def plot_all_data(path, data, arena, note):

    for gt in data:
        datasets = {}
        color_cycle = itertools.cycle(flymad_plot.EXP_COLORS)

        laser_powers_sorted = sorted(data[gt],
                                     cmp=flymad_analysis.cmp_laser,
                                     reverse=True)

        for order, laser in enumerate(laser_powers_sorted):

            #also sort to make cross-activation first
            cross_activation = (re.match('[0-9]+iru$',laser) and gt.endswith('chrim')) or \
                               (re.match('[0-9]+ru$',laser) and gt.endswith('trp'))

            gtdf = data[gt][laser][gt]

            laser_desc = flymad_analysis.laser_desc(laser)
            datasets[laser] = dict(
                xaxis=gtdf['mean']['t'].values,
                value=gtdf['mean']['Vfwd'].values,
                std=gtdf['std']['Vfwd'].values,
                n=gtdf['n']['Vfwd'].values,
                label=laser_desc,
                order=50 if cross_activation else order,
                color=color_cycle.next(),
                N=len(gtdf['df']['obj_id'].unique()),
                df=gtdf['df'],
            )

        if 1:
            if gt == "50660chrim":
                cgt = "50660"
                gtdf = data[cgt]["350iru"][cgt]
                datasets['control'] = dict(
                    xaxis=gtdf['mean']['t'].values,
                    value=gtdf['mean']['Vfwd'].values,
                    std=gtdf['std']['Vfwd'].values,
                    n=gtdf['n']['Vfwd'].values,
                    label=flymad_analysis.human_label(cgt),  #laser_desc,
                    order=100,
                    color=flymad_plot.BLACK,
                    N=len(gtdf['df']['obj_id'].unique()),
                    df=gtdf['df'],
                )

        figure_title = "Moonwalker Thorax %s (%s)" % (gt, smoothstr)

        fig = plt.figure(figure_title, figsize=(10, 8))
        ax = fig.add_subplot(1, 1, 1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(
            ax,
            targetbetween=dict(xaxis=gtdf['first']['t'].values,
                               where=gtdf['first']['laser_state'].values > 0),
            sem=True,
            downsample=5,
            note="%s\n%s\n" % (gt, note),
            individual={
                k: {
                    'groupby': ('obj_id', 'trial'),
                    'xaxis': 't',
                    'yaxis': 'Vfwd'
                }
                for k in datasets
            },
            individual_title=figure_title + ' Individual Traces',
            **datasets)

        ax.axhline(color='k', linestyle='--', alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_%s.png" % gt),
                    bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_%s.svg" % gt),
                    bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(
                path, "moonwalker_%s_individual_%s.png" % (gt, efigname)),
                         bbox_inches='tight')
def plot_cross_activation_only(path, data, arena, note):

    PLOTS = [
        ('50660chrim', {
            'activation': '350ru',
            'cross_activation': '350iru'
        }),
        ('50660trp', {
            'activation': '434iru',
            'cross_activation': '350ru'
        }),
        ('50660trp', {
            'activation': '350iru',
            'cross_activation': '350ru'
        }),
    ]

    for gt, lasers in PLOTS:
        figname = 'vs'.join(lasers.values())

        alaser = lasers['activation']
        adf = data[gt][alaser][gt]
        claser = lasers['cross_activation']
        cdf = data[gt][claser][gt]
        datasets = {
            'activation':
            dict(xaxis=adf['mean']['t'].values,
                 value=adf['mean']['Vfwd'].values,
                 std=adf['std']['Vfwd'].values,
                 n=adf['n']['Vfwd'].values,
                 label='Activation (%s)' % flymad_analysis.laser_desc(alaser),
                 order=0,
                 color=flymad_plot.RED,
                 N=len(adf['df']['obj_id'].unique()),
                 df=adf['df']),
            'cross_activation':
            dict(xaxis=cdf['mean']['t'].values,
                 value=cdf['mean']['Vfwd'].values,
                 std=cdf['std']['Vfwd'].values,
                 n=cdf['n']['Vfwd'].values,
                 label='Cross Activation (%s)' %
                 flymad_analysis.laser_desc(claser),
                 order=1,
                 color=flymad_plot.BLACK,
                 N=len(cdf['df']['obj_id'].unique()),
                 df=cdf['df']),
        }

        figure_title = "Moonwalker Thorax Crosstalk %s (%s)" % (gt, figname)

        fig = plt.figure(figure_title, figsize=(10, 8))
        ax = fig.add_subplot(1, 1, 1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(
            ax,
            targetbetween=dict(xaxis=adf['first']['t'].values,
                               where=adf['first']['laser_state'].values > 0),
            sem=True,
            downsample=5,
            note="%s\n%s\n" % (gt, note),
            individual={
                k: {
                    'groupby': ('obj_id', 'trial'),
                    'xaxis': 't',
                    'yaxis': 'Vfwd'
                }
                for k in datasets
            },
            individual_title=figure_title + ' Individual Traces',
            **datasets)

        ax.axhline(color='k', linestyle='--', alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(
            path, "moonwalker_%s_%s.png" % (gt, figname)),
                    bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(
            path, "moonwalker_%s_%s.svg" % (gt, figname)),
                    bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(
                path, "moonwalker_%s_%s_individual_%s.png" %
                (gt, figname, efigname)),
                         bbox_inches='tight')
def plot_all_data(path, data, arena, note):

    for gt in data:
        datasets = {}
        color_cycle = itertools.cycle(flymad_plot.EXP_COLORS)

        laser_powers_sorted = sorted(data[gt], cmp=flymad_analysis.cmp_laser, reverse=True)

        for order,laser in enumerate(laser_powers_sorted):

            #also sort to make cross-activation first
            cross_activation = (re.match('[0-9]+iru$',laser) and gt.endswith('chrim')) or \
                               (re.match('[0-9]+ru$',laser) and gt.endswith('trp'))

            gtdf = data[gt][laser][gt]

            laser_desc = flymad_analysis.laser_desc(laser)
            datasets[laser] = dict(xaxis=gtdf['mean']['t'].values,
                                   value=gtdf['mean']['Vfwd'].values,
                                   std=gtdf['std']['Vfwd'].values,
                                   n=gtdf['n']['Vfwd'].values,
                                   label=laser_desc,
                                   order=50 if cross_activation else order,
                                   color=color_cycle.next(),
                                   N=len(gtdf['df']['obj_id'].unique()),
                                   df=gtdf['df'],
            )

        if 1:
            if gt == "50660chrim":
                cgt = "50660"
                gtdf = data[cgt]["350iru"][cgt]
                datasets['control'] = dict(xaxis=gtdf['mean']['t'].values,
                                   value=gtdf['mean']['Vfwd'].values,
                                   std=gtdf['std']['Vfwd'].values,
                                   n=gtdf['n']['Vfwd'].values,
                                   label=flymad_analysis.human_label(cgt),#laser_desc,
                                   order=100,
                                   color=flymad_plot.BLACK,
                                   N=len(gtdf['df']['obj_id'].unique()),
                                   df=gtdf['df'],
            )

        figure_title = "Moonwalker Thorax %s (%s)" % (gt,smoothstr)

        fig = plt.figure(figure_title, figsize=(10,8))
        ax = fig.add_subplot(1,1,1)
        l, axs, figs = flymad_plot.plot_timeseries_with_activation(ax,
                            targetbetween=dict(xaxis=gtdf['first']['t'].values,
                                               where=gtdf['first']['laser_state'].values>0),
                            sem=True,
                            downsample=5,
                            note="%s\n%s\n" % (gt,note),
                            individual={k:{'groupby':('obj_id','trial'),'xaxis':'t','yaxis':'Vfwd'} for k in datasets},
                            individual_title=figure_title + ' Individual Traces',
                            **datasets
        )

        ax.axhline(color='k', linestyle='--',alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s.png" % gt), bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s.svg" % gt), bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_individual_%s.png" % (gt, efigname)), bbox_inches='tight')
def plot_cross_activation_only(path, data, arena, note):

    PLOTS = [('50660chrim',{'activation':'350ru','cross_activation':'350iru'}),
             ('50660trp',{'activation':'434iru','cross_activation':'350ru'}),
             ('50660trp',{'activation':'350iru','cross_activation':'350ru'}),
    ]

    for gt,lasers in PLOTS:
        figname = 'vs'.join(lasers.values())

        alaser = lasers['activation']
        adf = data[gt][alaser][gt]
        claser = lasers['cross_activation']
        cdf = data[gt][claser][gt]
        datasets = {
            'activation':dict(xaxis=adf['mean']['t'].values,
                              value=adf['mean']['Vfwd'].values,
                              std=adf['std']['Vfwd'].values,
                              n=adf['n']['Vfwd'].values,
                              label='Activation (%s)' % flymad_analysis.laser_desc(alaser),
                              order=0,
                              color=flymad_plot.RED,
                              N=len(adf['df']['obj_id'].unique()),
                              df=adf['df']),
            'cross_activation':dict(
                              xaxis=cdf['mean']['t'].values,
                              value=cdf['mean']['Vfwd'].values,
                              std=cdf['std']['Vfwd'].values,
                              n=cdf['n']['Vfwd'].values,
                              label='Cross Activation (%s)' % flymad_analysis.laser_desc(claser),
                              order=1,
                              color=flymad_plot.BLACK,
                              N=len(cdf['df']['obj_id'].unique()),
                              df=cdf['df']),
        }

        figure_title = "Moonwalker Thorax Crosstalk %s (%s)" % (gt,figname)

        fig = plt.figure(figure_title, figsize=(10,8))
        ax = fig.add_subplot(1,1,1)
        l,axs, figs = flymad_plot.plot_timeseries_with_activation(ax,
                    targetbetween=dict(xaxis=adf['first']['t'].values,
                                       where=adf['first']['laser_state'].values>0),
                    sem=True,
                    downsample=5,
                    note="%s\n%s\n" % (gt,note),
                    individual={k:{'groupby':('obj_id','trial'),'xaxis':'t','yaxis':'Vfwd'} for k in datasets},
                    individual_title=figure_title + ' Individual Traces',
                    **datasets
        )

        ax.axhline(color='k', linestyle='--',alpha=0.8)
        ax.set_ylim(YLIM)
        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Fwd Velocity (%s/s)' % arena.unit)
        ax.set_xlim(XLIM)

        flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s.png" % (gt, figname)), bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s.svg" % (gt, figname)), bbox_inches='tight')

        for efigname, efig in figs.iteritems():
            efig.savefig(flymad_plot.get_plotpath(path,"moonwalker_%s_%s_individual_%s.png" % (gt, figname, efigname)), bbox_inches='tight')
def plot_all_data(path, data, arena, note, laser='350iru'):

    ORDER = ["50660trp", "50660", "wtrp"]
    COLORS = {
        "50660trp": flymad_plot.RED,
        "50660": flymad_plot.BLACK,
        "wtrp": flymad_plot.BLUE
    }

    datasets = {}

    figure_title = "Moonwalker"
    fig = plt.figure(figure_title, figsize=TS_FIGSIZE)
    ax = fig.add_subplot(1, 1, 1)

    for gt in data:
        gtdf = data[gt][laser][gt]
        datasets[gt] = dict(
            xaxis=gtdf['mean']['t'].values,
            value=gtdf['mean']['Vfwd'].values,
            std=gtdf['std']['Vfwd'].values,
            n=gtdf['n']['Vfwd'].values,
            order=ORDER.index(gt),
            label=flymad_analysis.human_label(gt),
            color=COLORS[gt],
            N=len(gtdf['df']['obj_id'].unique()),
            df=gtdf['df'],
        )

    l, axs, figs = flymad_plot.plot_timeseries_with_activation(
        ax,
        targetbetween=dict(
            xaxis=data['50660trp'][laser]['50660trp']['first']['t'].values,
            where=data['50660trp'][laser]['50660trp']['first']
            ['laser_state'].values > 0),
        downsample=5,
        sem=True,
        note="%s\n" % (note, ),
        individual={
            k: {
                'groupby': ('obj_id', 'trial'),
                'xaxis': 't',
                'yaxis': 'Vfwd'
            }
            for k in datasets
        },
        individual_title=figure_title + ' Individual Traces',
        **datasets)

    ax.axhline(color='k', linestyle='--', alpha=0.8)
    ax.set_ylim(YLIM)
    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Forward velocity (%s/s)' % arena.unit)
    ax.set_xlim(XLIM)

    flymad_plot.retick_relabel_axis(ax, XTICKS, YTICKS)

    fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_simple.png"),
                bbox_inches='tight')
    fig.savefig(flymad_plot.get_plotpath(path, "moonwalker_simple.svg"),
                bbox_inches='tight')

    for efigname, efig in figs.iteritems():
        efig.savefig(flymad_plot.get_plotpath(
            path, "moonwalker_simple_individual_%s.png" % efigname),
                     bbox_inches='tight')
Beispiel #10
0
def plot_data(path, data):
    ci_html_buf = ''

    for exp_name in data:
        gts = data[exp_name].keys()

        laser = '130ht'
        gts_string = 'vs'.join(gts)
        figname = laser + '_' + gts_string

        fig = plt.figure("Song (%s)" % figname,figsize=(10,6))
        ax = fig.add_subplot(1,1,1)

        datasets = {}
        for gt in gts:

            if flymad_analysis.genotype_is_exp(gt):
                color = flymad_plot.RED
                order = 1
            elif flymad_analysis.genotype_is_ctrl(gt):
                color = flymad_plot.BLACK
                order = 2
            elif flymad_analysis.genotype_is_trp_ctrl(gt):
                order = 3
                color = flymad_plot.BLUE
            else:
                color = 'cyan'
                order = 0

            gtdf = data[exp_name][gt]
            datasets[gt] = dict(xaxis=gtdf['mean']['t'].values,
                                value=gtdf['mean']['zx'].values,
                                std=gtdf['std']['zx'].values,
                                n=gtdf['n']['zx'].values,
                                order=order,
                                df=gtdf,
                                label=flymad_analysis.human_label(gt),
                                color=color,
                                N=len(gtdf['df']['obj_id'].unique()))

        pvalue_buf = ''

        for gt in datasets:
            label=flymad_analysis.human_label(gt)
            if '>' not in label:
                continue

            # OK, this is a Gal4 + UAS - do head vs thorax stats
            gtdf = data[exp_name][gt]['df']
            ci_data = do_cum_incidence(gtdf, label)
            ci_html_buf += ci_data['buf']

            ax_cum = ci_data['ax']
            spine_placer(ax_cum, location='left,bottom' )

            ax_cum.set_ylabel('Fraction extending wing (%)')
            ax_cum.set_xlabel('Time (s)')

            note = '%s\n%s\np-value: %.3g\n%d flies\nn=%d, %d'%(label,
                                                                madplot.p2stars(ci_data['p_value']),
                                                            ci_data['p_value'],
                                                            len(gtdf['obj_id'].unique()),
                                                            ci_data['n_head'],
                                                            ci_data['n_thorax'])
            ax_cum.text(0, 1, #top left
                        note,
                        fontsize=10,
                        horizontalalignment='left',
                        verticalalignment='top',
                        transform=ax_cum.transAxes,
                        zorder=0)

            ci_data['fig'].savefig(flymad_plot.get_plotpath(path,"song_cum_inc_%s.png" % figname),
                                    bbox_inches='tight')
            ci_data['fig'].savefig(flymad_plot.get_plotpath(path,"song_cum_inc_%s.svg" % figname),
                                    bbox_inches='tight')


#            for i in range(len(head_times)):
#                head_values = gtdf[gtdf['t']==head_times[i]]
#                thorax_values = gtdf[gtdf['t']==thorax_times[i]]
#                test1 = head_values['zx'].values
#                test2 = thorax_values['zx'].values
#                hval, pval = kruskal(test1, test2)
#                pvalue_buf += 'Pulse %d: Head vs thorax WEI p-value: %.3g (n=%d, %d)\n'%(
#                    i+1, pval, len(test1), len(test2) )

        #all experiments used identical activation times
        headtargetbetween = dict(xaxis=data['pIP10']['wtrpmyc']['first']['t'].values,
                                 where=data['pIP10']['wtrpmyc']['first']['ttm'].values > 0)
        thoraxtargetbetween = dict(xaxis=data['pIP10']['wtrpmyc']['first']['t'].values,
                                   where=data['pIP10']['wtrpmyc']['first']['ttm'].values < 0)

        flymad_plot.plot_timeseries_with_activation(ax,
                    targetbetween=[headtargetbetween,thoraxtargetbetween],
                    sem=True,
                                                    note=pvalue_buf,
                    **datasets
        )

        ax.set_xlabel('Time (s)')
        ax.set_ylabel('Wing extension index')
        ax.set_ylim([-0.05,0.4] if gts_string == "40347vswtrpmycvs40347trpmyc" else [-0.05,1.0])
        ax.set_xlim([-10,180])

        flymad_plot.retick_relabel_axis(ax, [0, 60, 120, 180],
                [0, 0.2, 0.4] if gts_string == "40347vswtrpmycvs40347trpmyc" else [0, 0.5, 1])

        fig.savefig(flymad_plot.get_plotpath(path,"song_%s.png" % figname), bbox_inches='tight')
        fig.savefig(flymad_plot.get_plotpath(path,"song_%s.svg" % figname), bbox_inches='tight')

    with open(flymad_plot.get_plotpath(path,"song_cum_in.html"),mode='w') as fd:
        fd.write(ci_html_buf)
Beispiel #11
0
def plot_data(path, data, arena, note):

    LABELS = {'OK371shits-130h':'OK371>ShibireTS (head)',
              'OK371shits-nolaser':'Control',
              'OK371shits-130t':'OK371>ShibireTS (thorax)',
    }

    COLORS = {'OK371shits-130h':flymad_plot.RED,
              'OK371shits-nolaser':flymad_plot.BLACK,
              'OK371shits-130t':flymad_plot.ORANGE,
    }

    ORDERS = {'OK371shits-130h':2,
              'OK371shits-nolaser':4,
              'OK371shits-130t':3,
    }


    fig2 = plt.figure("Speed")
    ax = fig2.add_subplot(1,1,1)

    datasets = {}
    for gt in data:
        gtdf = data[gt]
        datasets[gt] = dict(xaxis=gtdf['mean']['t'].values,
                            value=gtdf['mean']['v'].values,
                            std=gtdf['std']['v'].values,
                            n=gtdf['n']['v'].values,
                            label=LABELS[gt],
                            color=COLORS[gt],
                            order=ORDERS[gt],
                            df=gtdf['df'],
                            N=len(gtdf['df']['obj_id'].unique()))

    ctrlfirst = data['OK371shits-nolaser']['first']

    result_d = flymad_plot.plot_timeseries_with_activation(ax,
                targetbetween=dict(xaxis=ctrlfirst['t'].values,
                                   where=ctrlfirst['laser_state'].values>0),
                downsample=5,
                sem=True,
                note="OK371shits\n%s\n" % note,
                individual={k:{'groupby':'obj_id','xaxis':'t','yaxis':'v'} for k in datasets},
                individual_title='Speed Individual Traces',
                return_dict=True,
                **datasets
    )
    figs = result_d['figs']

    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Speed (%s/s)' % arena.unit)
    ax.set_xlim([-15, 30])
    ax.set_ylim([0, 18])

    flymad_plot.retick_relabel_axis(ax, [-15, 0, 15, 30], [0, 5, 10, 15])

    fig2.savefig(flymad_plot.get_plotpath(path,"speed_plot.png"), bbox_inches='tight')
    fig2.savefig(flymad_plot.get_plotpath(path,"speed_plot.svg"), bbox_inches='tight')

    for efigname, efig in figs.iteritems():
        efig.savefig(flymad_plot.get_plotpath(path,"speed_plot_individual_%s.png" % efigname), bbox_inches='tight')
Beispiel #12
0
def plot_data(path, data, arena, note):

    LABELS = {
        'OK371shits-130h': 'OK371>ShibireTS (head)',
        'OK371shits-nolaser': 'Control',
        'OK371shits-130t': 'OK371>ShibireTS (thorax)',
    }

    COLORS = {
        'OK371shits-130h': flymad_plot.RED,
        'OK371shits-nolaser': flymad_plot.BLACK,
        'OK371shits-130t': flymad_plot.ORANGE,
    }

    ORDERS = {
        'OK371shits-130h': 2,
        'OK371shits-nolaser': 4,
        'OK371shits-130t': 3,
    }

    fig2 = plt.figure("Speed")
    ax = fig2.add_subplot(1, 1, 1)

    datasets = {}
    for gt in data:
        gtdf = data[gt]
        datasets[gt] = dict(xaxis=gtdf['mean']['t'].values,
                            value=gtdf['mean']['v'].values,
                            std=gtdf['std']['v'].values,
                            n=gtdf['n']['v'].values,
                            label=LABELS[gt],
                            color=COLORS[gt],
                            order=ORDERS[gt],
                            df=gtdf['df'],
                            N=len(gtdf['df']['obj_id'].unique()))

    ctrlfirst = data['OK371shits-nolaser']['first']

    result_d = flymad_plot.plot_timeseries_with_activation(
        ax,
        targetbetween=dict(xaxis=ctrlfirst['t'].values,
                           where=ctrlfirst['laser_state'].values > 0),
        downsample=5,
        sem=True,
        note="OK371shits\n%s\n" % note,
        individual={
            k: {
                'groupby': 'obj_id',
                'xaxis': 't',
                'yaxis': 'v'
            }
            for k in datasets
        },
        individual_title='Speed Individual Traces',
        return_dict=True,
        **datasets)
    figs = result_d['figs']

    ax.set_xlabel('Time (s)')
    ax.set_ylabel('Speed (%s/s)' % arena.unit)
    ax.set_xlim([-15, 30])
    ax.set_ylim([0, 18])

    flymad_plot.retick_relabel_axis(ax, [-15, 0, 15, 30], [0, 5, 10, 15])

    fig2.savefig(flymad_plot.get_plotpath(path, "speed_plot.png"),
                 bbox_inches='tight')
    fig2.savefig(flymad_plot.get_plotpath(path, "speed_plot.svg"),
                 bbox_inches='tight')

    for efigname, efig in figs.iteritems():
        efig.savefig(flymad_plot.get_plotpath(
            path, "speed_plot_individual_%s.png" % efigname),
                     bbox_inches='tight')
Beispiel #13
0
def plot_data(arena, path, smoothstr, data):

    COLORS = {"NINE":flymad_plot.RED,
              "CSSHITS":flymad_plot.BLUE,
              "NINGal4":flymad_plot.GREEN,
              'pooled controls':flymad_plot.BLACK,
              }
    ORDERS = {"NINE":1,"pooled controls":2,"NINGal4":3,"CSSHITS":4}
    LABELS = {"NINE":"NINE>ShiTS","pooled controls":"Controls","NINGal4":"Gal4-control","CSSHITS":"ShiTS-control"}

    # ---- pool controls ------------
    data['pooled controls'] = copy.deepcopy(data['CSSHITS'])
    assert np.allclose(data['NINGal4']['save_times'], data['pooled controls']['save_times'])


    # copy 'NINGal4' data into pooled controls
    for dname in data['NINGal4']:
        for row in data['NINGal4'][dname]:
            if dname in ['save_times','stimulus_velocity']:
                continue
            elif dname=='chunk':
                warnings.warn('not updating old chunk data for pooled controls')
            else:
                data['pooled controls'][dname].append(row)
    # for row in data['NINGal4']['chunk']:
    #     for key in row:
    #         data['pooled controls']['chunk'][key].append(row[key])

    # ----- raw timeseries plots ------------

    fig_angular_vel = plt.figure()
    fig_linear_vel = plt.figure()

    fig_summary_angular = plt.figure()
    ax_summary_angular = fig_summary_angular.add_subplot(211)
    ax_summary_linear = fig_summary_angular.add_subplot(212)
    pool_stats = collections.defaultdict(list)

    #order = ['NINE', 'CSSHITS', 'NINGal4']
    order = ['NINE', 'pooled controls']
    n_subplots = len(order)
    ax = None
    ax_angular_vel = fig_angular_vel.add_subplot(111)
    ax_linear_vel = fig_linear_vel.add_subplot(111)

    did_stimulus_plot = False
    plot_angular_datasets = collections.OrderedDict()
    plot_linear_datasets = collections.OrderedDict()

    for gti,gt in enumerate(order):

        # --- calculate stimulus -----------
        stim_times, stim_vel = data[gt]['stimulus_velocity']
        if 1:
            '''
            # 10 revolutions take 25 seconds at standard speed
            real_stim_vel = 10*2*np.pi/25.0 # 10 revolutions/second
            print 'real_stim_vel',real_stim_vel
            print 'gain[0]',real_stim_vel/stim_vel[100]
            print 'gain[1]',real_stim_vel/stim_vel[1001]
            '''
            gain = 0.00083775 # found using above
            stim_vel = gain*stim_vel

        if not did_stimulus_plot:
            ax_angular_vel.plot( stim_times,
                                 stim_vel*R2D,flymad_plot.ORANGE,
                                 lw=2, label='Stimulus', clip_on=False)
            did_stimulus_plot = True

        transition_idxs = np.nonzero(abs(stim_vel[1:]-stim_vel[:-1]))[0]
        #print 'stim_times[transition_idxs]',stim_times[transition_idxs]
        n_transitions = len(transition_idxs)

        # ---- done calculating stimulus ---

        all_angular_vel_timeseries = np.array(data[gt]['timeseries_angular_vel'])
        all_linear_vel_timeseries = np.array(data[gt]['timeseries_vel'])
        times = data[gt]['save_times']
        mean_angular_timeseries = np.mean( all_angular_vel_timeseries, axis=0 )
        error_angular_timeseries = np.std( all_angular_vel_timeseries, axis=0 )
        mean_linear_timeseries = np.mean( all_linear_vel_timeseries, axis=0 )
        error_linear_timeseries = np.std( all_linear_vel_timeseries, axis=0 )

        if 1:
            bin_data = []
            ang_means = []
            ang_stds = []
            lin_means = []
            lin_stds = []
            for i in range(n_transitions):
                this_data = dict(index=i,
                                 angular_velocity_values=[],
                                 linear_velocity_values=[],
                                 )
                start_time = stim_times[transition_idxs[i]]
                if (i+1)<n_transitions:
                    stop_time = stim_times[transition_idxs[i+1]]
                else:
                    # final bin
                    stop_time = stim_times[-1]
                #print 'start_time, stop_time',start_time, stop_time
                start_idx = np.argmin(abs(times - start_time))
                stop_idx =  np.argmin(abs(times - stop_time))
                #print 'times[start_idx], times[stop_idx]',times[start_idx], times[stop_idx]
                this_data['start_time'] = times[start_idx]
                this_data['stop_time'] = times[stop_idx]
                assert len( all_angular_vel_timeseries)== len(all_linear_vel_timeseries)
                for j in range( len(all_angular_vel_timeseries)):
                    this_angular_timeseries = all_angular_vel_timeseries[j]
                    this_linear_timeseries =  all_linear_vel_timeseries[j]

                    good = ~np.isnan(this_angular_timeseries[start_idx:stop_idx])
                    ang = np.mean(this_angular_timeseries[start_idx:stop_idx][good])
                    lin = np.mean(this_linear_timeseries[start_idx:stop_idx][good])

                    this_data['angular_velocity_values'].append( ang )
                    this_data['linear_velocity_values'].append( lin )

                    pool_stats['gt'].append(gt)
                    pool_stats['bin_number'].append(i)
                    pool_stats['bin_start'].append( this_data['start_time'] )
                    pool_stats['bin_stop'].append( this_data['stop_time'] )
                    pool_stats['nth_fly_of_gt'].append(j)
                    pool_stats['mean_angular_velocity_during_bin'].append( ang )
                    pool_stats['mean_linear_velocity_during_bin'].append( lin )

                this_data[ 'ang_mean' ] = np.mean( this_data['angular_velocity_values'] )
                this_data[ 'ang_std' ] = np.std( this_data['angular_velocity_values'] )
                this_data[ 'lin_mean' ] = np.mean( this_data['linear_velocity_values'] )
                this_data[ 'lin_std' ] = np.std( this_data['linear_velocity_values'] )
                bin_data.append( this_data )
                ang_means.append( this_data['ang_mean'] )
                ang_stds.append( this_data['ang_std'] )
                lin_means.append( this_data['lin_mean'] )
                lin_stds.append( this_data['lin_std'] )

            ang_means = np.array(ang_means)
            ang_stds  = np.array(ang_stds)
            lin_means = np.array(lin_means)
            lin_stds  = np.array(lin_stds)

            ax_summary_angular.axhline(0,color='black')
            ax_summary_angular.plot( ang_means*R2D, label=gt, color=COLORS[gt] )
            ax_summary_angular.plot( (ang_means+ang_stds)*R2D, color=COLORS[gt] )
            ax_summary_angular.plot( (ang_means-ang_stds)*R2D, color=COLORS[gt] )

            ax_summary_linear.axhline(0,color='black')
            ax_summary_linear.plot( lin_means, label=gt, color=COLORS[gt] )
            ax_summary_linear.plot( lin_means+lin_stds, color=COLORS[gt] )
            ax_summary_linear.plot( lin_means-lin_stds, color=COLORS[gt] )

        this_data_angular_vel = {'xaxis':times,
                                 'value':mean_angular_timeseries*R2D,
                                 'std':error_angular_timeseries*R2D,
                                 'label':gt,
                                 'color':COLORS[gt],
                                 'label':LABELS[gt],
                                 'order':ORDERS[gt],
                                 }
        this_data_linear_vel = {'xaxis':times,
                                'value':mean_linear_timeseries,
                                'std':error_linear_timeseries,
                                'label':gt,
                                'color':COLORS[gt],
                                'label':LABELS[gt],
                                'order':ORDERS[gt],
                                }
        plot_angular_datasets[gt]=this_data_angular_vel
        plot_linear_datasets[gt]=this_data_linear_vel

    tb = {'xaxis':data['pooled controls']['save_times'],
          'where':data['pooled controls']['laser_power']>1,
          }
    flymad_plot.plot_timeseries_with_activation(
                                     ax_angular_vel,
                                     downsample=2,
                                     targetbetween=[tb],
                                     **plot_angular_datasets)
    ax_angular_vel.axhline(0,color='black')
    ax_angular_vel.set_xlabel('Time (s)')
    ax_angular_vel.set_ylabel('Angular velocity (deg/s)')
    ax_angular_vel.set_ylim(-200,200)
    ax_angular_vel.set_xlim(0,300)

    flymad_plot.retick_relabel_axis(ax_angular_vel, [0,150,300], [-200,0,200])

    figname = 'optoresponse_ts_angular_vel'
    fig_angular_vel.savefig(flymad_plot.get_plotpath(path,"%s.png" % figname), bbox_inches='tight')
    fig_angular_vel.savefig(flymad_plot.get_plotpath(path,"%s.svg" % figname), bbox_inches='tight')

    flymad_plot.plot_timeseries_with_activation(
                                     ax_linear_vel,
                                     targetbetween=[tb],
                                     downsample=3,
                                     **plot_linear_datasets)

    ax_linear_vel.set_ylim([0,40])
    ax_linear_vel.set_xlim(0,300)
#    ax_linear_vel.spines['bottom'].set_bounds(0,330.0)
#    ax_linear_vel.spines['bottom'].set_linewidth(0.3)
#    ax_linear_vel.spines['left'].set_linewidth(0.3)
    ax_linear_vel.set_xlabel('Time (s)')
    ax_linear_vel.set_ylabel('Velocity (%s/s)' % arena.unit)

    flymad_plot.retick_relabel_axis(ax_linear_vel, [0,150,300], [0,20,40])

    figname = 'optoresponse_ts_linear_vel'
    fig_linear_vel.savefig(flymad_plot.get_plotpath(path,"%s.png" % figname), bbox_inches='tight')
    fig_linear_vel.savefig(flymad_plot.get_plotpath(path,"%s.svg" % figname), bbox_inches='tight')

    if 1:

        def p2star(p):
            if   p < 0.001:
                result =  '***'
            elif p < 0.01:
                result =  '**'
            elif p < 0.05:
                result =  '*'
            else:
                result =  ''
            result += ' %.3g'%p
            return result
        # calculate p values
        pool_stats_df = pd.DataFrame(pool_stats)
        df_fname = 'optomotor_stats.df'
        pool_stats_df.to_pickle(df_fname)
        sig = do_stats( df_fname )
        for i in range(len(sig['bin_num'])):
            bin_num = sig['bin_num'][i]
            p_value = sig['ang'][i]
            ax_summary_angular.text( bin_num,
                                     0,
                                     p2star(p_value))

            p_value = sig['ang_zero'][i]
            ax_summary_angular.text( bin_num,
                                     -100,
                                     p2star(p_value))

            ax_summary_angular.text( bin_num,
                                     140,
                                     '%s - %s'%(sig['bin_start'][i],
                                                sig['bin_stop'][i]),
                                     )
            p_value = sig['lin'][i]
            ax_summary_linear.text( bin_num,
                                    5,
                                    p2star(p_value))


    ax_summary_angular.set_ylabel('angular velocity (deg/sec)')
    ax_summary_linear.set_ylabel('velocity (mm/sec)')
    ax_summary_linear.set_xlabel('bin number')


    fig_fname = 'fig_summary.png'
    fig_summary_angular.savefig(fig_fname)
    print 'saved',fig_fname
    fig_fname = 'fig_summary.svg'
    fig_summary_angular.savefig(fig_fname)
    print 'saved',fig_fname
    fig_fname = 'fig_summary.pdf'
    fig_summary_angular.savefig(fig_fname)
    print 'saved',fig_fname


    # -----------------------

    # plot individual timeseries

    for gti,gt in enumerate(order):
        fig_gt = plt.figure('indiv_timeseries_'+gt)
        n_rows = len(data[gt]['timeseries_vel'])
        n_cols = 2 # linear and angular
        save_times = data[gt]['save_times']
        ax_lin = None
        ax_ang = None
        for i in range(n_rows):
            angular_vel = data[gt]['timeseries_angular_vel'][i]
            linear_vel = data[gt]['timeseries_vel'][i]

            ax_lin = fig_gt.add_subplot( n_rows, 2, i*2+1, sharex=ax_lin, sharey=ax_lin )
            ax_ang = fig_gt.add_subplot( n_rows, 2, i*2+2, sharex=ax_ang, sharey=ax_ang )
            ax_ang.axhline(0,color='black')

            ax_lin.plot( save_times, linear_vel )
            ax_ang.plot( save_times, angular_vel*R2D )

            bag = os.path.basename(data[gt]['bag_fname'][i])
            ax_lin.text(50,50,'lin '+bag)
            ax_ang.text(50,3*R2D,'ang '+bag)

            ax_lin.set_ylim(0,50)
            ax_ang.set_ylim(-300,300)
        plt.figtext(0.05, 0.05, gt)
        fname = 'individual_%s.pdf'%gt
        fig_gt.savefig(fname)
        print 'saved',fname

    # -----------------------

    if 1:
        return

    # - John's category stuff ----------------

    #pprint.pprint(data)

    figt = plt.figure('dtheta %s' % (smoothstr), figsize=(16,10))
    axt = figt.add_subplot(1,1,1)
    figv = plt.figure('v %s' % (smoothstr), figsize=(16,10))
    axv = figv.add_subplot(1,1,1)


    for gt in order:
        xdata = []
        ytdata = []
        yvdata = []
        for xlabel in sorted(data[gt]['chunk']):
            xloc = int(xlabel[0])
            for mean_dtheta,mean_v in data[gt]['chunk'][xlabel]:
                xdata.append(xloc)
                ytdata.append(mean_dtheta)
                yvdata.append(mean_v)

#        print gt,xdata,ydata

        axt.plot(xdata,ytdata,'o',color=COLORS[gt],markersize=5,label=gt)
        axv.plot(xdata,yvdata,'o',color=COLORS[gt],markersize=5,label=gt)

    for ax in (axt,axv):
        ax.legend()
        ax.set_xlim(0,9)

        ax.set_xticks([int(s[0]) for s in sorted(data["NINE"]['chunk'])])
        ax.set_xticklabels([s[2:] for s in sorted(data["NINE"]['chunk'])])

    figpath = os.path.join(path,'dtheta_%s.png' % (smoothstr))
    figt.savefig(figpath)
    print "wrote", figpath
    figpath = os.path.join(path,'v_%s.png' % (smoothstr))
    figv.savefig(figpath)
    print "wrote", figpath