def plot_number_observer_with_matplotlib(*args, **kwargs):
import matplotlib.pylab as plt<EOL>import numpy<EOL>import collections<EOL>special_keys = ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:x>", "<STR_LIT:y>", "<STR_LIT:filename>")<EOL>plot_opts = {key: value for key, value in kwargs.items()<EOL>if key not in special_keys}<EOL>if '<STR_LIT>' in plt.rcParams.keys():<EOL><INDENT>color_cycle = [prop['<STR_LIT>'] for prop in plt.rcParams['<STR_LIT>']]<EOL><DEDENT>else:<EOL><INDENT>color_cycle = plt.rcParams['<STR_LIT>']<EOL><DEDENT>if "<STR_LIT:y>" in kwargs.keys() and isinstance(kwargs["<STR_LIT:y>"], str):<EOL><INDENT>kwargs["<STR_LIT:y>"] = (kwargs["<STR_LIT:y>"], )<EOL><DEDENT>fig = plt.figure()<EOL>ax = fig.add_subplot(<NUM_LIT>)<EOL>if len(args) > <NUM_LIT:1> and isinstance(args[<NUM_LIT:1>], str):<EOL><INDENT>if len(args) % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>observers = [(args[i], args[i + <NUM_LIT:1>]) for i in range(<NUM_LIT:0>, len(args), <NUM_LIT:2>)]<EOL><DEDENT>else:<EOL><INDENT>observers = [(args[i], args[i + <NUM_LIT:1>]) for i in range(<NUM_LIT:0>, len(args) - <NUM_LIT:1>, <NUM_LIT:2>)]<EOL>observers.append(args[-<NUM_LIT:1>], None)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>observers = [(obs, None) for obs in args]<EOL><DEDENT>color_map = {}<EOL>data, xidx = None, <NUM_LIT:0><EOL>for obs, fmt in observers:<EOL><INDENT>if isinstance(obs, types.FunctionType):<EOL><INDENT>if data is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = [obs(xi) for xi in data[xidx]]<EOL>opts = plot_opts.copy()<EOL>label = obs.__name__<EOL>opts["<STR_LIT:label>"] = label<EOL>if label not in color_map.keys():<EOL><INDENT>color_map[label] = color_cycle[len(color_map) % len(color_cycle)]<EOL>opts["<STR_LIT:label>"] = label<EOL><DEDENT>opts["<STR_LIT>"] = color_map[label]<EOL>if fmt is None:<EOL><INDENT>ax.plot(data[xidx], y, **opts)<EOL><DEDENT>else:<EOL><INDENT>ax.plot(data[xidx], y, fmt, **opts)<EOL><DEDENT>continue<EOL><DEDENT>data = numpy.array(obs.data()).T<EOL>try:<EOL><INDENT>err = obs.error().T<EOL><DEDENT>except AttributeError:<EOL><INDENT>err = None<EOL><DEDENT>if "<STR_LIT:x>" in kwargs.keys():<EOL><INDENT>targets = [sp.serial() for sp in obs.targets()]<EOL>if kwargs["<STR_LIT:x>"] not in targets:<EOL><INDENT>raise ValueError("<STR_LIT>".fomrat(kwargs["<STR_LIT:x>"]))<EOL><DEDENT>xidx = targets.index(kwargs["<STR_LIT:x>"]) + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>xidx = <NUM_LIT:0><EOL><DEDENT>if "<STR_LIT:y>" in kwargs.keys():<EOL><INDENT>targets = [sp.serial() for sp in obs.targets()]<EOL>targets = [(targets.index(serial), serial)<EOL>for serial in kwargs["<STR_LIT:y>"] if serial in targets]<EOL><DEDENT>else:<EOL><INDENT>targets = [sp.serial() for sp in obs.targets()]<EOL>targets = list(enumerate(targets))<EOL><DEDENT>for idx, serial in targets:<EOL><INDENT>opts = plot_opts.copy()<EOL>label = serial<EOL>if len(label) > <NUM_LIT:0> and label[<NUM_LIT:0>] == '<STR_LIT:_>':<EOL><INDENT>label = '<STR_LIT>' + label[<NUM_LIT:1>:]  <EOL><DEDENT>if label not in color_map.keys():<EOL><INDENT>color_map[label] = color_cycle[len(color_map) % len(color_cycle)]<EOL>opts["<STR_LIT:label>"] = label<EOL><DEDENT>opts["<STR_LIT>"] = color_map[label]<EOL>if err is None:<EOL><INDENT>if fmt is None:<EOL><INDENT>ax.plot(data[xidx], data[idx + <NUM_LIT:1>], **opts)<EOL><DEDENT>else:<EOL><INDENT>ax.plot(data[xidx], data[idx + <NUM_LIT:1>], fmt, **opts)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if fmt is None:<EOL><INDENT>ax.errorbar(data[xidx], data[idx + <NUM_LIT:1>],<EOL>xerr=(None if xidx == <NUM_LIT:0> else err[xidx]), yerr=err[idx + <NUM_LIT:1>],<EOL>**opts)<EOL><DEDENT>else:<EOL><INDENT>ax.errorbar(data[xidx], data[idx + <NUM_LIT:1>],<EOL>xerr=(None if xidx == <NUM_LIT:0> else err[xidx]), yerr=err[idx + <NUM_LIT:1>],<EOL>fmt=fmt, **opts)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if "<STR_LIT>" not in kwargs.keys() or (kwargs["<STR_LIT>"] is not None and kwargs["<STR_LIT>"] is not False):<EOL><INDENT>legend_opts = {"<STR_LIT>": "<STR_LIT>", "<STR_LIT>": True}<EOL>if "<STR_LIT>" in kwargs and isinstance(kwargs["<STR_LIT>"], dict):<EOL><INDENT>legend_opts.update(kwargs["<STR_LIT>"])<EOL><DEDENT>ax.legend(*ax.get_legend_handles_labels(), **legend_opts)<EOL><DEDENT>if "<STR_LIT>" in kwargs.keys():<EOL><INDENT>ax.set_xlabel(kwargs["<STR_LIT>"])<EOL><DEDENT>elif "<STR_LIT:x>" in kwargs.keys():<EOL><INDENT>ax.set_xlabel("<STR_LIT>".format(kwargs["<STR_LIT:x>"]))<EOL><DEDENT>else:<EOL><INDENT>ax.set_xlabel("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in kwargs.keys():<EOL><INDENT>ax.set_ylabel(kwargs["<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>ax.set_ylabel("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in kwargs.keys():<EOL><INDENT>ax.set_xlim(kwargs["<STR_LIT>"])<EOL><DEDENT>if "<STR_LIT>" in kwargs.keys():<EOL><INDENT>ax.set_ylim(kwargs["<STR_LIT>"])<EOL><DEDENT>if "<STR_LIT:filename>" in kwargs.keys():<EOL><INDENT>plt.savefig(kwargs["<STR_LIT:filename>"])<EOL><DEDENT>else:<EOL><INDENT>plt.show()<EOL><DEDENT>
Generate a plot from NumberObservers and show it on IPython notebook
with matplotlib.

Parameters
----------
obs : NumberObserver (e.g. FixedIntervalNumberObserver)
fmt : str, optional
opt : dict, optional
    matplotlib plot options.

Examples
--------
>>> plot_number_observer(obs1)
>>> plot_number_observer(obs1, 'o')
>>> plot_number_observer(obs1, obs2, obs3, {'linewidth': 2})
>>> plot_number_observer(obs1, 'k-', obs2, 'k--')