예제 #1
0
def generic_plot_sequence(r, plotter, space, sequence,
                          axis0=None, annotation=None):

    axis = plotter.axis_for_sequence(space, sequence)

    if axis[0] == axis[1]:
        dx = 1
#         dy = 1
        axis = (axis[0] - dx, axis[1] + dx, axis[2], axis[3])
    axis = enlarge(axis, 0.15)
    if axis0 is not None:
        axis = join_axes(axis, axis0)

    for i, x in enumerate(sequence):
        caption = space.format(x)
        caption = None
        with r.plot('S%d' % i, caption=caption) as pylab:
            plotter.plot(pylab, axis, space, x)
            if annotation is not None:
                annotation(pylab, axis)

            xlabel, ylabel = plotter.get_xylabels(space)
            try:
                if xlabel:
                    pylab.xlabel(xlabel)
                if ylabel:
                    pylab.ylabel(ylabel)

            except UnicodeDecodeError as e:
                print xlabel, xlabel.__repr__(), ylabel, ylabel.__repr__(), e
            
            if (axis[0] != axis[1]) or (axis[2] != axis[3]):
                pylab.axis(axis)
예제 #2
0
파일: plotter_urr.py 프로젝트: kannode/mcdp
    def axis_for_sequence(self, space, seq):
        self.check_plot_space(space)

        points2d = [[self.toR2(self.P_to_S(_)) for _ in s.minimals]
                    for s in seq]
        axes = [get_bounds(_) for _ in points2d]
        return enlarge(functools.reduce(reduce_bounds, axes), 0.1)
예제 #3
0
    def axis_for_sequence(self, space, seq):
        self.check_plot_space(space)

        #         R = Rcomp()

        maxy = 1000.0

        def limit(p):  # XXX trick for Top?
            y = p
            y = min(y, maxy)
            return y

        ys = [max([limit(self.P_to_S(_)) for _ in s.minimals]) for s in seq]
        axes = (-1, 1, 0, max(ys))

        return enlarge(axes, 0.1)
예제 #4
0
    def axis_for_sequence(self, space, seq):
        self.check_plot_space(space)

        R = Rcomp()

        maxy = 1000.0

        def limit(p):  # XXX trick for Top?
            y = p
            y = min(y, maxy)
            return y

        ys = [max([limit(self.P_to_S(_)) for _ in s.minimals]) for s in seq]
        axes = (-1, 1, 0, max(ys))

        return enlarge(axes, 0.1)
예제 #5
0
def generic_plot(f, space, value):
    plotters = get_all_available_plotters()

    es = []
    for name, plotter in plotters.items():
        try:
            plotter.check_plot_space(space)
        except NotPlottable as e:
            es.append(e)
            # print('Plotter %r cannot plot %r:\n%s' % (name, space, e))
            continue

        axis = plotter.axis_for_sequence(space, [value])
        axis = enlarge(axis, 0.15)
        #print('enlarged:  %s' % str(axis))
        with f.plot(name) as pylab:
            plotter.plot(pylab, axis, space, value, params={})
            pylab.axis(axis)
예제 #6
0
def generic_plot(f, space, value):
    plotters = get_all_available_plotters()

    es = []
    for name, plotter in plotters.items():
        try:
            plotter.check_plot_space(space)
        except NotPlottable as e:
            es.append(e)
            # print('Plotter %r cannot plot %r:\n%s' % (name, space, e))
            continue

        axis = plotter.axis_for_sequence(space, [value])
        axis = enlarge(axis, 0.15)
        #print('enlarged:  %s' % str(axis))
        with f.plot(name) as pylab:
            plotter.plot(pylab, axis, space, value, params={})
            pylab.axis(axis)
예제 #7
0
def generic_plot_sequence(r,
                          plotter,
                          space,
                          sequence,
                          axis0=None,
                          annotation=None):

    axis = plotter.axis_for_sequence(space, sequence)

    if axis[0] == axis[1]:
        dx = 1
        #         dy = 1
        axis = (axis[0] - dx, axis[1] + dx, axis[2], axis[3])
    axis = enlarge(axis, 0.15)
    if axis0 is not None:
        axis = join_axes(axis, axis0)

    for i, x in enumerate(sequence):
        caption = space.format(x)
        caption = None
        with r.plot('S%d' % i, caption=caption) as pylab:
            plotter.plot(pylab, axis, space, x)
            if annotation is not None:
                annotation(pylab, axis)

            xlabel, ylabel = plotter.get_xylabels(space)
            try:
                if xlabel:
                    pylab.xlabel(xlabel)
                if ylabel:
                    pylab.ylabel(ylabel)

            except UnicodeDecodeError:
                # print xlabel, xlabel.__repr__(), ylabel, ylabel.__repr__(), e
                pass

            if (axis[0] != axis[1]) or (axis[2] != axis[3]):
                pylab.axis(axis)
예제 #8
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
예제 #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
    def axis_for_sequence(self, space, seq):
        self.check_plot_space(space)

        points2d = [[self.toR2(self.P_to_S(_)) for _ in s.minimals] for s in seq]
        axes = [get_bounds(_) for _ in points2d]
        return enlarge(functools.reduce(reduce_bounds, axes), 0.1)