def make_lcfplot(dgroup, form, nfit=0):
    """make larch plot commands to plot LCF fit from form"""
    form['group'] = dgroup.groupname
    form['filename'] = dgroup.filename

    form['nfit'] = nfit
    form['label'] = label = 'Fit #%2.2d' % (nfit+1)
    form['plotopt'] = 'show_norm=True'
    if form['arrayname'] == 'dmude':
        form['plotopt'] = 'show_deriv=True'

    erange = form['ehi'] - form['elo']
    form['pemin'] = 10*int( (form['elo'] - 5 - erange/4.0) / 10.0)
    form['pemax'] = 10*int( (form['ehi'] + 5 + erange/4.0) / 10.0)


    cmds = ["""plot_mu({group:s}, {plotopt:s}, delay_draw=True, label='data',
    emin={pemin:.1f}, emax={pemax:.1f}, title='{filename:s}, {label:s}')"""]

    if hasattr(dgroup, 'lcf_result'):
        with_comps = True # "Components" in form['plotchoice']
        delay = 'delay_draw=True' if with_comps else 'delay_draw=False'
        xarr = "{group:s}.lcf_result[{nfit:d}].xdata"
        yfit = "{group:s}.lcf_result[{nfit:d}].yfit"
        ycmp = "{group:s}.lcf_result[{nfit:d}].ycomps"
        cmds.append("plot(%s, %s, label='%s', zorder=30, %s)" % (xarr, yfit, label, delay))
        ncomps = len(dgroup.lcf_result[nfit].ycomps)
        if with_comps:
            for i, key in enumerate(dgroup.lcf_result[nfit].ycomps):
                delay = 'delay_draw=False' if i==(ncomps-1) else 'delay_draw=True'
                cmds.append("plot(%s, %s['%s'], label='%s', %s)" % (xarr, ycmp, key, key, delay))

    # if form['show_e0']:
    #     cmds.append("plot_axvline({e0:1f}, color='#DDDDCC', zorder=-10)")
    if form['show_fitrange']:
        cmds.append("plot_axvline({elo:1f}, color='#EECCCC', zorder=-10)")
        cmds.append("plot_axvline({ehi:1f}, color='#EECCCC', zorder=-10)")

    script = "\n".join(cmds)
    return script.format(**form)