def __oplot_impl(top, xlabel_fct, ylabel_fct, legend_fct, obj, xticks_fct,
                 title_fct, *opt_list, **opt_dict):
    """
    A thin layer above pyplot.plot function that allows plotting objects with
    plot protocol as well as arrays.
    Options are the same as for the pyplot.plot function.
    """

    for curve_dict in plot_protocol_apply(obj, opt_dict, plt.xlim):

        import warnings
        if type in curve_dict:
            warnings.warn("The keyword 'type' is deprecated. Remove it.")
            curve_dict.pop('type', None)

        plt_fct = getattr(top, curve_dict.pop('plot_function', 'plot'))
        X = curve_dict.pop('xdata')
        Y = curve_dict.pop('ydata')

        # Sort out axis labels and legend
        xlabel = curve_dict.pop('xlabel', None)
        ylabel = curve_dict.pop('ylabel', None)
        xticks = curve_dict.pop('xticks', None)
        title = curve_dict.pop('title', None)
        if xlabel: xlabel_fct(xlabel)
        if ylabel: ylabel_fct(ylabel)
        if title: title_fct(title)
        if xticks: xticks_fct(*xticks, rotation=30)
        is_legend = curve_dict.pop('legend', True)

        try:
            if "zdata" in curve_dict.keys():
                Z = curve_dict.pop('zdata')
                plt_fct(X, Y, Z, *opt_list, **curve_dict)
            else:
                plt_fct(X, Y, *opt_list, **curve_dict)
        except TypeError, e:
            import re
            m = re.search('(?<=There is no line property )"(.*)"', str(e))
            if m:
                raise RuntimeError, "Plot option %s not understood: it is neither an option of the object to be plotted, nor a matplotlib option." % m.group(
                    0)
            else:
                raise

        if is_legend: legend_fct(loc=1)  # legend is built from the label
Ejemplo n.º 2
0
def __oplot_impl(top, xlabel_fct, ylabel_fct, legend_fct, obj, xticks_fct,  title_fct, *opt_list, **opt_dict):
    """
    A thin layer above pyplot.plot function that allows plotting objects with
    plot protocol as well as arrays.
    Options are the same as for the pyplot.plot function.
    """

    for curve_dict in plot_protocol_apply(obj, opt_dict, plt.xlim):

        import warnings
        if type in curve_dict:
            warnings.warn("The keyword 'type' is deprecated. Remove it.")
            curve_dict.pop('type',None)

        plt_fct = getattr(top, curve_dict.pop('plot_function', 'plot'))
        X = curve_dict.pop('xdata')
        Y = curve_dict.pop('ydata')

        # Sort out axis labels and legend
        xlabel = curve_dict.pop('xlabel',None)
        ylabel = curve_dict.pop('ylabel',None)
        xticks = curve_dict.pop('xticks',None)
        title = curve_dict.pop('title',None)
        if xlabel: xlabel_fct(xlabel)
        if ylabel: ylabel_fct(ylabel)
        if title: title_fct(title)
        if xticks: xticks_fct(*xticks, rotation=30)
        is_legend = curve_dict.pop('legend',True)

        try:
         if "zdata" in curve_dict.keys():
            Z = curve_dict.pop('zdata')
            plt_fct(X, Y, Z, *opt_list, **curve_dict)
         else:
            plt_fct(X, Y, *opt_list, **curve_dict)
        except TypeError, e:
            import re
            m = re.search('(?<=There is no line property )"(.*)"', str(e))
            if m:
                raise RuntimeError, "Plot option %s not understood: it is neither an option of the object to be plotted, nor a matplotlib option." % m.group(0)
            else:
                raise

        if is_legend: legend_fct(loc=1)  # legend is built from the label
Ejemplo n.º 3
0
def __oplot_impl(plotFnt, xlabelFnt, ylabelFnt, legendFnt, *ob_list, **OptionsDict):
    """
    A thin layer above pyplot.plot function that allows plotting objects with
    plot protocol as well as arrays. 
    Options are the same as for the pyplot.plot function.
    """

    def objs():  # filter the arguments for the format strings ...
        i, l = 0, []
        while i < len(ob_list):
            if i < len(ob_list) - 1 and type(ob_list[i + 1]) == type(""):
                res = ob_list[i], [ob_list[i + 1]]
                i += 2
            else:
                res = ob_list[i], []
                i += 1
            yield res

    for ob, OptionsList in objs():
        opt = OptionsDict.copy()  # the plot protocol will consume the dict....
        # ob2 = eval_expr_or_pass (ob) # if it is a lazy_expr, it is time to evaluate it !
        for curvedata in plot_protocol_apply(ob, opt, plt.xlim):
            X, Y = curvedata["xdata"], curvedata["ydata"]
            d = {"label": curvedata["label"]}
            d.update(opt)
            try:
                plotFnt(X, Y, *OptionsList, **d)
            except TypeError, e:
                import re

                m = re.search('(?<=There is no line property )"(.*)"', str(e))
                if m:
                    raise RuntimeError, "Option %s is not understood in plot function : it is not an option of the object to be plotted, nor a matplotlib option" % m.group(
                        0
                    )
                else:
                    raise
            if "xlabel" in curvedata:
                xlabelFnt(curvedata["xlabel"], fontsize=20)
            if "ylabel" in curvedata:
                ylabelFnt(curvedata["ylabel"], fontsize=20)
Ejemplo n.º 4
0
def __oplot_impl(plot_fct, xlabel_fct, ylabel_fct, legend_fct, *ob_list,
                 **opt_dict):
    """
    A thin layer above pyplot.plot function that allows plotting objects with
    plot protocol as well as arrays. 
    Options are the same as for the pyplot.plot function.
    """
    def objs():  # filter the arguments for the format strings ...
        i, l = 0, []
        while i < len(ob_list):
            if i < len(ob_list) - 1 and type(ob_list[i + 1]) == type(""):
                res = ob_list[i], [ob_list[i + 1]]
                i += 2
            else:
                res = ob_list[i], []
                i += 1
            yield res

    for ob, OptionsList in objs():
        opt = opt_dict.copy()  # the plot protocol will consume the dict....
        #ob2 = eval_expr_or_pass (ob) # if it is a lazy_expr, it is time to evaluate it !
        for curvedata in plot_protocol_apply(ob, opt, plt.xlim):
            X, Y = curvedata['xdata'], curvedata['ydata']
            d = {'label': curvedata['label']}
            d.update(opt)
            try:
                plot_fct(X, Y, *OptionsList, **d)
            except TypeError, e:
                import re
                m = re.search('(?<=There is no line property )"(.*)"', str(e))
                if m:
                    raise RuntimeError, "Option %s is not understood in plot function : it is not an option of the object to be plotted, nor a matplotlib option" % m.group(
                        0)
                else:
                    raise
            if 'xlabel' in curvedata:
                xlabel_fct(curvedata['xlabel'], fontsize=20)
            if 'ylabel' in curvedata:
                ylabel_fct(curvedata['ylabel'], fontsize=20)