|
| 1 | +""" |
| 2 | +Base module for plotting engines to override and register |
| 3 | +with pandas. |
| 4 | +""" |
| 5 | +from pandas.core.base import PandasObject |
| 6 | + |
| 7 | +engines = {} |
| 8 | + |
| 9 | + |
| 10 | +def register_engine(name, kind, engine): |
| 11 | + # XXX: get rid of the kind parameter |
| 12 | + global engines |
| 13 | + engines[(name, kind)] = engine |
| 14 | + |
| 15 | + |
| 16 | +def deregister_engine(name, kind): |
| 17 | + # XXX: get rid of the kind parameter |
| 18 | + global engines |
| 19 | + engines.pop((name, kind)) |
| 20 | + |
| 21 | + |
| 22 | +def get_engine(kind): |
| 23 | + # XXX: get rid of the kind parameter |
| 24 | + from pandas import get_option |
| 25 | + |
| 26 | + active = get_option('plotting.engine') |
| 27 | + if active == 'auto': |
| 28 | + active = 'matplotlib' |
| 29 | + |
| 30 | + return engines[(active, kind)] |
| 31 | + |
| 32 | + |
| 33 | +class Dispatcher(object): |
| 34 | + |
| 35 | + def __init__(self, data): |
| 36 | + self._data = data |
| 37 | + |
| 38 | + def __call__(self, *args, **kwargs): |
| 39 | + kind = 'frame' if self._data.ndim == 2 else 'series' |
| 40 | + engine = get_engine(kind) |
| 41 | + return engine(self._data)(*args, **kwargs) |
| 42 | + |
| 43 | + def __getattribute__(self, name): |
| 44 | + if name == '_data': |
| 45 | + return object.__getattribute__(self, name) |
| 46 | + kind = 'frame' if self._data.ndim == 2 else 'series' |
| 47 | + |
| 48 | + engine = get_engine(kind)(self._data) |
| 49 | + return getattr(engine, name) |
| 50 | + |
| 51 | + |
| 52 | +class BasePlotMethods(PandasObject): |
| 53 | + |
| 54 | + def __init__(self, data): |
| 55 | + self._data = data |
| 56 | + |
| 57 | + def __call__(self, *args, **kwargs): |
| 58 | + """Make a plot""" |
| 59 | + raise NotImplementedError |
| 60 | + |
| 61 | + def area(self, **kwargs): |
| 62 | + raise NotImplementedError("This backend doesn't support this method") |
| 63 | + |
| 64 | + def bar(self, **kwargs): |
| 65 | + raise NotImplementedError("This backend doesn't support this method") |
| 66 | + |
| 67 | + def barh(self, **kwargs): |
| 68 | + raise NotImplementedError("This backend doesn't support this method") |
| 69 | + |
| 70 | + def box(self, **kwargs): |
| 71 | + raise NotImplementedError("This backend doesn't support this method") |
| 72 | + |
| 73 | + def density(self, **kwargs): |
| 74 | + raise NotImplementedError("This backend doesn't support this method") |
| 75 | + |
| 76 | + def hist(self, **kwargs): |
| 77 | + raise NotImplementedError("This backend doesn't support this method") |
| 78 | + |
| 79 | + def line(self, **kwargs): |
| 80 | + raise NotImplementedError("This backend doesn't support this method") |
| 81 | + |
| 82 | + def pie(self, **kwargs): |
| 83 | + raise NotImplementedError("This backend doesn't support this method") |
| 84 | + |
| 85 | + |
| 86 | +class SeriesPlotMethods(BasePlotMethods): |
| 87 | + pass |
| 88 | + |
| 89 | + |
| 90 | +class FramePlotMethods(BasePlotMethods): |
| 91 | + |
| 92 | + def hexbin(self, x, y, **kwargs): |
| 93 | + raise NotImplementedError("This backend doesn't support this method") |
| 94 | + |
| 95 | + def scatter(self, x, y, **kwargs): |
| 96 | + raise NotImplementedError("This backend doesn't support this method") |
0 commit comments