From e401bd2100fd915d5d245b02467ab8c0ec9216fd Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 28 Sep 2014 15:59:52 -0400 Subject: [PATCH] WIP : draft of replacement for pyplot pyplot_nng replaces most of pyplot plotting functions, a few things (like plt.subplots and the other axes/figure generation functions) need to be interactive gives a auto-redraw wrapper for explicitly using axes, but forces you through a functional interface rather than the OO interface. --- lib/matplotlib/pyplot_nng.py | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/matplotlib/pyplot_nng.py diff --git a/lib/matplotlib/pyplot_nng.py b/lib/matplotlib/pyplot_nng.py new file mode 100644 index 000000000000..88f16abddacb --- /dev/null +++ b/lib/matplotlib/pyplot_nng.py @@ -0,0 +1,48 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import six +import matplotlib.pyplot as plt # to grab figure management stuff +from matplotlib.axes import Axes +import functools + + +# apparently, raw object objects use slots. +class Dummy(object): + pass + +pyplot_nng = Dummy() +interactive = Dummy() + + +def interactive_wrapper(func): + @functools.wraps(func) + def inner(ax, *args, **kwargs): + ret_list = func(ax, *args, **kwargs) + ax.figure.canvas.draw() + return ret_list + + return inner + + +def wrap_for_pyplot(func): + def inner(*args, **kwargs): + ax = plt.gca() + art_list = func(ax, *args, **kwargs) + ax.figure.canvas.draw() + return art_list + + inner.__name__ = func.__name__ + # This should be modified to strip the docs + # if the axes as the first argument is documented + inner.__doc__ = func.__doc__ + return inner + +funcs_to_wrap = [atr for atr in + (getattr(Axes, atr_name) for atr_name in dir(Axes) + if not atr_name.startswith('_')) + if callable(atr)] + +for f in funcs_to_wrap: + setattr(pyplot_nng, f.__name__, wrap_for_pyplot(f)) + setattr(interactive, f.__name__, interactive_wrapper(f))