コード例 #1
0
ファイル: drone_unc2.py プロジェクト: rusi/mcdp
def report(data):
    from matplotlib import pylab
    ieee_fonts_zoom3(pylab)
    r = Report()

    print('reading iterations')
    num_iterations_L = [
        get_num_iterations(res_i['traceL']) for res_i in data['results']
    ]
    num_iterations_U = [
        get_num_iterations(res_i['traceU']) for res_i in data['results']
    ]

    def get_mass(res):
        if not res.minimals:
            return None
        return list(res.minimals)[0]

    res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']])
    res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']])

    accuracy = np.array(res_U) - np.array(res_L)

    num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U)

    print res_L
    print res_U
    print num_iterations_L
    print num_iterations_U

    intervals = data['intervals']

    print('Plotting')
    f = r.figure('fig1', cols=2)

    LOWER = 'bo-'
    UPPER = 'mo-'

    markers = dict(markeredgecolor='none',
                   markerfacecolor='black',
                   markersize=6,
                   marker='o')
    LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False)
    UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False)
    LOWER2.update(markers)
    UPPER2.update(markers)
    color_resources = '#700000'
    # color_functions = '#007000'
    color_tolerance = '#000000'

    attrs = dict(clip_on=False)

    fig = dict(figsize=(4.5, 4))
    fig_tall = dict(figsize=(3.5, 7))

    label_tolerance = u'tolerance α [mW]'
    #     label_tolerance = 'tolerance $\\alpha$ [mW]'

    with f.plot('fig_num_iterations', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, num_iterations_L, **LOWER2)
        pylab.plot(intervals, num_iterations_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('iterations')

    with f.plot('fig_num_iterations_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, num_iterations_L, **LOWER2)
        pylab.loglog(intervals, num_iterations_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('iterations')

    with f.plot('mass', **fig_tall) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, res_L, LOWER, **attrs)
        pylab.plot(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass3', **fig_tall) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, res_L, **LOWER2)
        pylab.plot(intervals, res_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass3log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.semilogx(intervals, res_L, **LOWER2)
        pylab.semilogx(intervals, res_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, res_L, LOWER, **attrs)
        pylab.loglog(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass2', **fig) as pylab:
        ieee_spines_zoom3(pylab)

        mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5
        err = (res_U - res_L) / 2

        e = pylab.errorbar(intervals,
                           mean,
                           yerr=err,
                           color='black',
                           linewidth=2,
                           linestyle="None",
                           **attrs)
        #         plotline: Line2D instance #         x, y plot markers and/or line
        #         caplines: list of error bar cap#         Line2D instances
        #         barlinecols: list of         LineCollection instances for the horizontal and vertical error ranges.
        e[0].set_clip_on(False)
        for b in e[1]:
            b.set_clip_on(False)
        for b in e[2]:
            b.set_clip_on(False)
            b.set_linewidth(2)

        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass2_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, res_L, LOWER, **attrs)
        pylab.loglog(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('accuracy', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(accuracy, num_iterations, 'o', **attrs)
        pylab.ylabel('iterations')
        pylab.xlabel('solution uncertainty [g]')

    with f.plot('accuracy_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(accuracy, num_iterations, 'o', **attrs)
        pylab.ylabel('iterations')
        pylab.xlabel('solution uncertainty [g]')

    return r
コード例 #2
0
def do_axes(pylab):
    pylab.xlabel('missions')
    pylab.ylabel('capacity [J]')
    set_axis_colors(pylab, color_functions, color_functions)
コード例 #3
0
def do_axes_drone(pylab):
    pylab.xlabel('missions')
    pylab.ylabel('endurance')
    set_axis_colors(pylab, color_functions, color_functions)
コード例 #4
0
ファイル: plot_drone.py プロジェクト: AndreaCensi/mcdp
def report_plane2(data):
    matplotlib_settings()
    cs = CommonStats(data)
    r = Report()
    
    what_to_plot_res = dict(total_mass="kg", total_cost="USD")
    what_to_plot_fun = dict(endurance="Wh", extra_payload="g")

    plot_all_directions(r, queries=data['queries'], results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    
    fig1 = dict(figsize=(3, 3)) 
    fig2 = dict(figsize=(4, 4))
    
    fnames = ('endurance', 'extra_payload')
    rnames = ('total_cost', 'total_mass')
    
    axis = (108, 145,  0.05, 0.8)
    axis2 = (105, 111.5,  0.05, 0.27)
    fs, rs = cs.iterate(fnames, rnames)
    
    colors = get_colors(len(fs))
    f = r.figure()
    
    with f.plot('resources1', **fig1) as pylab:
        ieee_spines_zoom3(pylab)
  
        for i, ((f1, f2), resources) in enumerate(zip(fs, rs)):
            color = colors[i]
            if resources:
                marker = 'k.'
            else:
                marker = 'x'
            pylab.plot(f1, f2, marker, markerfacecolor=color, clip_on=False)
  
        pylab.xlabel('endurance [min]')
        pylab.ylabel('extra_payload [g]')
#         pylab.xticks([0, 30, 60, 90, 120])
        set_axis_colors(pylab, color_functions, color_functions)
        

    params0 = dict(color_shadow=[1.0, 0.8, 0.8], markers='k.',
                       markers_params={})

    color_shadow = params0['color_shadow']
    markers = params0['markers']

    P = parse_poset('dimensionless x dimensionless')
    
    with f.plot('resources2', **fig2) as pylab:
        ieee_spines_zoom3(pylab)

        for i, resources in enumerate(rs):
            v = P.Us(resources)
            color = colors[i]
            plot_upset_R2(pylab, v, axis, extra_space_shadow=0,
                      color_shadow=color, markers=markers,
                      marker_params=dict(markerfacecolor=color))
        
        pylab.ylabel('total mass [kg]')
        pylab.xlabel('total cost [USD]')
        pylab.xticks([110, 120, 130, 140, 150])
#         pylab.yticks([0.2, 0.25, 0.3, 0.35])
        set_axis_colors(pylab, color_resources, color_resources)
        pylab.axis(axis)

    rs_subset = rs[:3]
    with f.plot('resources3', **fig2) as pylab:
        ieee_spines_zoom3(pylab)

        for i, resources in enumerate(rs_subset):
            v = P.Us(resources)
            color = colors[i]
            plot_upset_R2(pylab, v, axis2, extra_space_shadow=0,
                      color_shadow=color, markers=markers,
                      marker_params=dict(markerfacecolor=color))
        
        pylab.ylabel('total mass [kg]')
        pylab.xlabel('total cost [USD]')
        pylab.xticks([110, 110.5, 111,111.5,])
        set_axis_colors(pylab, color_resources, color_resources)

    return r
コード例 #5
0
def report(data):
    print('report()')
    from matplotlib import pylab

    ieee_fonts_zoom3(pylab)

    r = Report()

    num = np.array(data['n'])
    print num

    print('reading iterations')
    num_iterations_L = [
        get_num_iterations(res_i['traceL']) for res_i in data['results']
    ]
    num_iterations_U = [
        get_num_iterations(res_i['traceU']) for res_i in data['results']
    ]

    def get_mass(res):
        if not res.minimals:
            return np.inf
        return list(res.minimals)[0]

    res_L = np.array([get_mass(res_i['resL']) for res_i in data['results']])
    res_U = np.array([get_mass(res_i['resU']) for res_i in data['results']])

    accuracy = np.array(res_U) - np.array(res_L)

    num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U)

    print res_L
    print res_U
    print num_iterations_L
    print num_iterations_U

    print('Plotting')
    f = r.figure('fig1', cols=2)

    attrs = dict(clip_on=False)

    markers = dict(markeredgecolor='none',
                   markerfacecolor='black',
                   markersize=6,
                   marker='o')
    LOWER = dict(color='orange', linewidth=4, linestyle='-', clip_on=False)
    UPPER = dict(color='purple', linewidth=4, linestyle='-', clip_on=False)
    LOWER.update(markers)
    UPPER.update(markers)
    color_resources = '#700000'
    # color_functions = '#007000'
    color_tolerance = '#000000'

    fig = dict(figsize=(4.5, 3.4))

    with f.plot('fig_num_iterations', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(num, num_iterations_L, **LOWER)
        pylab.plot(num, num_iterations_U, **UPPER)
        pylab.ylabel('iterations')
        pylab.xlabel('n')

    if False:
        with f.plot('fig_num_iterations_log', **fig) as pylab:
            ieee_spines_zoom3(pylab)
            pylab.loglog(num, num_iterations_L, **LOWER)
            pylab.loglog(num, num_iterations_U, **UPPER)
            pylab.ylabel('iterations')
            pylab.xlabel('n')

    with f.plot('mass', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(num, res_L, **LOWER)
        pylab.plot(num, res_U, **UPPER)
        pylab.ylabel('total mass [g]')
        pylab.xlabel('n')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass2', **fig) as pylab:
        ieee_spines_zoom3(pylab)

        valid = np.isfinite(res_U)
        invalid = np.logical_not(valid)
        print valid

        res_L_valid = res_L[valid]
        res_U_valid = res_U[valid]
        num_valid = num[valid]

        mean = res_L_valid * 0.5 + res_U_valid * 0.5
        err = (res_U_valid - res_L_valid) / 2

        e = pylab.errorbar(num_valid,
                           mean,
                           yerr=err,
                           color='black',
                           linewidth=2,
                           linestyle="None",
                           **attrs)
        #         plotline: Line2D instance #         x, y plot markers and/or line
        #         caplines: list of error bar cap#         Line2D instances
        #         barlinecols: list of         LineCollection instances for the horizontal and vertical error ranges.
        e[0].set_clip_on(False)
        for b in e[1]:
            b.set_clip_on(False)
        for b in e[2]:
            b.set_clip_on(False)
            b.set_linewidth(2)

        num_invalid = num[invalid]
        res_L_invalid = res_L[invalid]
        max_y = pylab.axis()[3]
        for n, res_L in zip(num_invalid, res_L_invalid):
            pylab.plot([n, n], [max_y, res_L], '--', color='gray', **attrs)
        pylab.plot(num_invalid, res_L_invalid, 'ko', **attrs)

        pylab.xlabel('n')
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('accuracy', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(num_iterations, accuracy, 'o', **attrs)
        pylab.xlabel('iterations')
        pylab.ylabel('solution uncertainty [g]')

    return r
コード例 #6
0
ファイル: plot_trade_space.py プロジェクト: rusi/mcdp
 def do_axes(pylab):
     pylab.xlabel('resolution [pixels/deg]')
     pylab.ylabel('min_throughput [Hz]')
     set_axis_colors(pylab, color_functions, color_functions)
コード例 #7
0
ファイル: plot_batteries_choice.py プロジェクト: rusi/mcdp
def do_axes_drone(pylab):
    pylab.xlabel('missions')
    pylab.ylabel('endurance')
    set_axis_colors(pylab, color_functions, color_functions)
コード例 #8
0
ファイル: drone_unc2.py プロジェクト: AndreaCensi/mcdp
def report(data):
    from matplotlib import pylab
    ieee_fonts_zoom3(pylab)
    r = Report()

    print('reading iterations')
    num_iterations_L = [get_num_iterations(res_i['traceL']) for res_i in data['results']]
    num_iterations_U = [get_num_iterations(res_i['traceU']) for res_i in data['results']]

    def get_mass(res):
        if not res.minimals:
            return None
        return list(res.minimals)[0]

    res_L = np.array([ get_mass(res_i['resL']) for res_i in data['results']])
    res_U = np.array([ get_mass(res_i['resU']) for res_i in data['results']])

    accuracy = np.array(res_U) - np.array(res_L)

    num_iterations = np.array(num_iterations_L) + np.array(num_iterations_U)

    print res_L
    print res_U
    print num_iterations_L
    print num_iterations_U

    intervals = data['intervals']

    print('Plotting')
    f = r.figure('fig1', cols=2)

    LOWER = 'bo-'
    UPPER = 'mo-'

    markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6,
                   marker='o')
    LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False)
    UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False)
    LOWER2.update(markers)
    UPPER2.update(markers)
    color_resources = '#700000'
    # color_functions = '#007000'
    color_tolerance = '#000000'


    attrs = dict(clip_on=False)
    
    fig = dict(figsize=(4.5, 4))
    fig_tall = dict(figsize=(3.5    , 7))

    label_tolerance = u'tolerance α [mW]'
#     label_tolerance = 'tolerance $\\alpha$ [mW]'

    with f.plot('fig_num_iterations', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, num_iterations_L, **LOWER2)
        pylab.plot(intervals, num_iterations_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('iterations')

    with f.plot('fig_num_iterations_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, num_iterations_L, **LOWER2)
        pylab.loglog(intervals, num_iterations_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('iterations')

    with f.plot('mass', **fig_tall) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, res_L, LOWER, **attrs)
        pylab.plot(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass3', **fig_tall) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(intervals, res_L, **LOWER2)
        pylab.plot(intervals, res_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass3log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.semilogx(intervals, res_L, **LOWER2)
        pylab.semilogx(intervals, res_U, **UPPER2)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass_log', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, res_L, LOWER, **attrs)
        pylab.loglog(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass2', **fig) as pylab:
        ieee_spines_zoom3(pylab)

        mean = np.array(res_L) * 0.5 + np.array(res_U) * 0.5
        err = (res_U - res_L) / 2

        e = pylab.errorbar(intervals, mean, yerr=err,
                           color='black', linewidth=2,
                           linestyle="None", **attrs)
#         plotline: Line2D instance #         x, y plot markers and/or line
#         caplines: list of error bar cap#         Line2D instances
#         barlinecols: list of         LineCollection instances for the horizontal and vertical error ranges.
        e[0].set_clip_on(False)
        for b in e[1]:
            b.set_clip_on(False)
        for b in e[2]:
            b.set_clip_on(False)
            b.set_linewidth(2)

        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('mass2_log',  **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(intervals, res_L, LOWER, **attrs)
        pylab.loglog(intervals, res_U, UPPER, **attrs)
        pylab.xlabel(label_tolerance)
        pylab.ylabel('total mass [g]')
        set_axis_colors(pylab, color_tolerance, color_resources)

    with f.plot('accuracy',  **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.plot(accuracy, num_iterations, 'o', **attrs)
        pylab.ylabel('iterations')
        pylab.xlabel('solution uncertainty [g]')

    with f.plot('accuracy_log',  **fig) as pylab:
        ieee_spines_zoom3(pylab)
        pylab.loglog(accuracy, num_iterations, 'o', **attrs)
        pylab.ylabel('iterations')
        pylab.xlabel('solution uncertainty [g]')

    return r
コード例 #9
0
def _report_loop_sequence(report, R, sips, converged, do_movie):
    """
        Returns a dictionary dict(str: list of png data)
    """
    sequences = {}
    
    UR = UpperSets(R)
    from matplotlib import pylab
    ieee_fonts(pylab)
    RepRepDefaults.savefig_params = dict(dpi=400, bbox_inches='tight', 
                                         pad_inches=0.01, transparent=False)

    figsize = (2, 2)
    
    try:
        available_plotters = list(get_plotters(get_all_available_plotters(), UR))
    except NotPlottable as e:
        msg = 'Could not find plotter for space UR = %s.' % UR
        raise_wrapped(DPInternalError, e, msg , UR=UR, compact=True)
    
    with report.subsection('sip') as r2:
        for name, plotter in available_plotters:
            sequences[name] = [] # sequence of png
            f = r2.figure(name, cols=5)

            axis = plotter.axis_for_sequence(UR, sips)

            axis = list(axis)
            axis[0] = 0.0
            axis[2] = 0.0
            axis[1] = min(axis[1], 1000.0)
            axis[3] = min(axis[3], 1000.0)
            axis = tuple(axis)

            visualized_axis = enlarge(axis, extra_space_top * 2)

            for i, sip in enumerate(sips):
                with f.plot('step%03d' % i, figsize=figsize) as pylab:
                    logger.debug('Plotting iteration %d/%d' % (i, len(sips)))
                    ieee_spines(pylab)
                    c_orange = '#FFA500'
                    c_red = [1, 0.5, 0.5]
                    plotter.plot(pylab, axis, UR, R.U(R.get_bottom()),
                                 params=dict(color_shadow=c_red, markers=None))
                    marker_params = dict(markersize=5, markeredgecolor='none')
                    plotter.plot(pylab, axis, UR, sip,
                                 params=dict(color_shadow=c_orange,
                                             markers_params=marker_params))
                    conv = converged[i]
                    c_blue = [0.6, 0.6, 1.0]
                    plotter.plot(pylab, axis, UR, conv,
                                 params=dict(color_shadow=c_blue))
                    
                    for c in conv.minimals:
                        p = plotter.toR2(c)
                        pylab.plot(p[0], p[1], 'go',
                                   markersize=5, markeredgecolor='none', 
                                   markerfacecolor='g', clip_on=False)
                    pylab.axis(visualized_axis)
                    from mcdp_ipython_utils.plotting import color_resources, set_axis_colors

                    set_axis_colors(pylab, color_resources, color_resources)

                if do_movie:
                    node = f.resolve_url('step%03d/png' % i)
                    png = node.raw_data
                    sequences[name].append(png)

    return sequences
コード例 #10
0
ファイル: plot_commons.py プロジェクト: AndreaCensi/mcdp
 def do_axes(pylab):
     pylab.xlabel(fname1)
     pylab.ylabel(fname2)
     set_axis_colors(pylab, color_functions, color_functions)
コード例 #11
0
ファイル: drone_unc1.py プロジェクト: AndreaCensi/mcdp
def report(res):

    r = Report()

    dataL = res['dataL']
    dataU = res['dataU']

    what_to_plot_res = dict(total_cost="USD", total_mass='kg')
    what_to_plot_fun = dict(endurance="hour", extra_payload="g")

    queries = dataL['queries']
    endurance = [q['endurance'] for q in queries]

    def get_value(data, field):
        for res in data['results']:
            a = to_numpy_array({field: 'kg'}, res)

            if len(a):
                a = min(a[field])
            else:
                a = None
            yield a


    from matplotlib import pylab
    ieee_fonts_zoom3(pylab)


    markers = dict(markeredgecolor='none', markerfacecolor='black', markersize=6,
                   marker='o')
    LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False)
    UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False)
    LOWER2.update(markers)
    UPPER2.update(markers)
    color_resources = '#700000'
    color_functions = '#007000'


    fig = dict(figsize=(4.5, 4))

    with r.plot('total_mass', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        total_massL = np.array(list(get_value(dataL, 'total_mass')))
        total_massU = np.array(list(get_value(dataU, 'total_mass')))
        print endurance
        print total_massL, total_massU
        pylab.plot(endurance, total_massL, **LOWER2)
        pylab.plot(endurance, total_massU, **UPPER2)
        set_axis_colors(pylab, color_functions, color_resources)
        pylab.xlabel('endurance [hours]')
        pylab.ylabel('total_mass [kg]')

    return r


    print('Plotting lower')
    with r.subsection('lower') as rL:
        plot_all_directions(rL,
                            queries=dataL['queries'],
                            results=dataL['results'],
                            what_to_plot_res=what_to_plot_res,
                            what_to_plot_fun=what_to_plot_fun)
    
    print('Plotting upper')
    with r.subsection('upper') as rU:
        plot_all_directions(rU,
                            queries=dataU['queries'],
                            results=dataU['results'],
                            what_to_plot_res=what_to_plot_res,
                            what_to_plot_fun=what_to_plot_fun)

    return r
コード例 #12
0
def report(res):

    r = Report()

    dataL = res['dataL']
    dataU = res['dataU']

    what_to_plot_res = dict(total_cost="USD", total_mass='kg')
    what_to_plot_fun = dict(endurance="hour", extra_payload="g")

    queries = dataL['queries']
    endurance = [q['endurance'] for q in queries]

    def get_value(data, field):
        for res in data['results']:
            a = to_numpy_array({field: 'kg'}, res)

            if len(a):
                a = min(a[field])
            else:
                a = None
            yield a

    from matplotlib import pylab
    ieee_fonts_zoom3(pylab)

    markers = dict(markeredgecolor='none',
                   markerfacecolor='black',
                   markersize=6,
                   marker='o')
    LOWER2 = dict(color='orange', linewidth=4, linestyle='-', clip_on=False)
    UPPER2 = dict(color='purple', linewidth=4, linestyle='-', clip_on=False)
    LOWER2.update(markers)
    UPPER2.update(markers)
    color_resources = '#700000'
    color_functions = '#007000'

    fig = dict(figsize=(4.5, 4))

    with r.plot('total_mass', **fig) as pylab:
        ieee_spines_zoom3(pylab)
        total_massL = np.array(list(get_value(dataL, 'total_mass')))
        total_massU = np.array(list(get_value(dataU, 'total_mass')))
        print endurance
        print total_massL, total_massU
        pylab.plot(endurance, total_massL, **LOWER2)
        pylab.plot(endurance, total_massU, **UPPER2)
        set_axis_colors(pylab, color_functions, color_resources)
        pylab.xlabel('endurance [hours]')
        pylab.ylabel('total_mass [kg]')

    return r

    print('Plotting lower')
    with r.subsection('lower') as rL:
        plot_all_directions(rL,
                            queries=dataL['queries'],
                            results=dataL['results'],
                            what_to_plot_res=what_to_plot_res,
                            what_to_plot_fun=what_to_plot_fun)

    print('Plotting upper')
    with r.subsection('upper') as rU:
        plot_all_directions(rU,
                            queries=dataU['queries'],
                            results=dataU['results'],
                            what_to_plot_res=what_to_plot_res,
                            what_to_plot_fun=what_to_plot_fun)

    return r
コード例 #13
0
ファイル: discrete_choices.py プロジェクト: rusi/mcdp
 def do_axes(pylab):
     from mcdp_ipython_utils.plotting import set_axis_colors    
     set_axis_colors(pylab, color_functions, color_functions)
コード例 #14
0
 def do_axes(pylab):
     pylab.xlabel(fname1)
     pylab.ylabel(fname2)
     set_axis_colors(pylab, color_functions, color_functions)
コード例 #15
0
ファイル: generic_report_utils.py プロジェクト: kannode/mcdp
def _report_loop_sequence(report, R, sips, converged, do_movie):
    """
        Returns a dictionary dict(str: list of png data)
    """
    sequences = {}

    UR = UpperSets(R)
    from matplotlib import pylab
    ieee_fonts(pylab)
    RepRepDefaults.savefig_params = dict(dpi=400,
                                         bbox_inches='tight',
                                         pad_inches=0.01,
                                         transparent=False)

    figsize = (2, 2)

    try:
        available_plotters = list(
            get_plotters(get_all_available_plotters(), UR))
    except NotPlottable as e:
        msg = 'Could not find plotter for space UR = %s.' % UR
        raise_wrapped(DPInternalError, e, msg, UR=UR, compact=True)

    with report.subsection('sip') as r2:
        for name, plotter in available_plotters:
            sequences[name] = []  # sequence of png
            f = r2.figure(name, cols=5)

            axis = plotter.axis_for_sequence(UR, sips)

            axis = list(axis)
            axis[0] = 0.0
            axis[2] = 0.0
            axis[1] = min(axis[1], 1000.0)
            axis[3] = min(axis[3], 1000.0)
            axis = tuple(axis)

            visualized_axis = enlarge(axis, extra_space_top * 2)

            for i, sip in enumerate(sips):
                with f.plot('step%03d' % i, figsize=figsize) as pylab:
                    logger.debug('Plotting iteration %d/%d' % (i, len(sips)))
                    ieee_spines(pylab)
                    c_orange = '#FFA500'
                    c_red = [1, 0.5, 0.5]
                    plotter.plot(pylab,
                                 axis,
                                 UR,
                                 R.U(R.get_bottom()),
                                 params=dict(color_shadow=c_red, markers=None))
                    marker_params = dict(markersize=5, markeredgecolor='none')
                    plotter.plot(pylab,
                                 axis,
                                 UR,
                                 sip,
                                 params=dict(color_shadow=c_orange,
                                             markers_params=marker_params))
                    conv = converged[i]
                    c_blue = [0.6, 0.6, 1.0]
                    plotter.plot(pylab,
                                 axis,
                                 UR,
                                 conv,
                                 params=dict(color_shadow=c_blue))

                    for c in conv.minimals:
                        p = plotter.toR2(c)
                        pylab.plot(p[0],
                                   p[1],
                                   'go',
                                   markersize=5,
                                   markeredgecolor='none',
                                   markerfacecolor='g',
                                   clip_on=False)
                    pylab.axis(visualized_axis)
                    from mcdp_ipython_utils.plotting import color_resources, set_axis_colors

                    set_axis_colors(pylab, color_resources, color_resources)

                if do_movie:
                    node = f.resolve_url('step%03d/png' % i)
                    png = node.raw_data
                    sequences[name].append(png)

    return sequences
コード例 #16
0
ファイル: plot_batteries_choice.py プロジェクト: rusi/mcdp
def do_axes(pylab):
    pylab.xlabel('missions')
    pylab.ylabel('capacity [J]')
    set_axis_colors(pylab, color_functions, color_functions)
コード例 #17
0
ファイル: discrete_choices.py プロジェクト: AndreaCensi/mcdp
    def do_axes(pylab):
        from mcdp_ipython_utils.plotting import set_axis_colors

        set_axis_colors(pylab, color_functions, color_functions)
コード例 #18
0
ファイル: plot_drone.py プロジェクト: rusi/mcdp
def report_plane2(data):
    matplotlib_settings()
    cs = CommonStats(data)
    r = Report()

    what_to_plot_res = dict(total_mass="kg", total_cost="USD")
    what_to_plot_fun = dict(endurance="Wh", extra_payload="g")

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)

    fig1 = dict(figsize=(3, 3))
    fig2 = dict(figsize=(4, 4))

    fnames = ('endurance', 'extra_payload')
    rnames = ('total_cost', 'total_mass')

    axis = (108, 145, 0.05, 0.8)
    axis2 = (105, 111.5, 0.05, 0.27)
    fs, rs = cs.iterate(fnames, rnames)

    colors = get_colors(len(fs))
    f = r.figure()

    with f.plot('resources1', **fig1) as pylab:
        ieee_spines_zoom3(pylab)

        for i, ((f1, f2), resources) in enumerate(zip(fs, rs)):
            color = colors[i]
            if resources:
                marker = 'k.'
            else:
                marker = 'x'
            pylab.plot(f1, f2, marker, markerfacecolor=color, clip_on=False)

        pylab.xlabel('endurance [min]')
        pylab.ylabel('extra_payload [g]')
        #         pylab.xticks([0, 30, 60, 90, 120])
        set_axis_colors(pylab, color_functions, color_functions)

    params0 = dict(color_shadow=[1.0, 0.8, 0.8],
                   markers='k.',
                   markers_params={})

    color_shadow = params0['color_shadow']
    markers = params0['markers']

    P = parse_poset('dimensionless x dimensionless')

    with f.plot('resources2', **fig2) as pylab:
        ieee_spines_zoom3(pylab)

        for i, resources in enumerate(rs):
            v = P.Us(resources)
            color = colors[i]
            plot_upset_R2(pylab,
                          v,
                          axis,
                          extra_space_shadow=0,
                          color_shadow=color,
                          markers=markers,
                          marker_params=dict(markerfacecolor=color))

        pylab.ylabel('total mass [kg]')
        pylab.xlabel('total cost [USD]')
        pylab.xticks([110, 120, 130, 140, 150])
        #         pylab.yticks([0.2, 0.25, 0.3, 0.35])
        set_axis_colors(pylab, color_resources, color_resources)
        pylab.axis(axis)

    rs_subset = rs[:3]
    with f.plot('resources3', **fig2) as pylab:
        ieee_spines_zoom3(pylab)

        for i, resources in enumerate(rs_subset):
            v = P.Us(resources)
            color = colors[i]
            plot_upset_R2(pylab,
                          v,
                          axis2,
                          extra_space_shadow=0,
                          color_shadow=color,
                          markers=markers,
                          marker_params=dict(markerfacecolor=color))

        pylab.ylabel('total mass [kg]')
        pylab.xlabel('total cost [USD]')
        pylab.xticks([
            110,
            110.5,
            111,
            111.5,
        ])
        set_axis_colors(pylab, color_resources, color_resources)

    return r