diff --git a/GPy/plotting/abstract_plotting_library.py b/GPy/plotting/abstract_plotting_library.py index 2bbb8dc4..35353f36 100644 --- a/GPy/plotting/abstract_plotting_library.py +++ b/GPy/plotting/abstract_plotting_library.py @@ -57,9 +57,19 @@ class AbstractPlottingLibrary(object): return self.__defaults #=============================================================================== - def get_new_canvas(self, projection='2d', legend=True, **kwargs): + def figure(self, nrows, ncols, **kwargs): + """ + Get a new figure with nrows and ncolumns subplots. + Does not initialize the canvases yet. + """ + raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library") + + def get_new_canvas(self, projection='2d', figure=None, col=1, row=1, **kwargs): """ Return a canvas, kwargupdate for your plotting library. + + if figure is not None, create a canvas in the figure + at subplot position (col, row). This method does two things, it creates an empty canvas and updates the kwargs (deletes the unnecessary kwargs) @@ -74,7 +84,7 @@ class AbstractPlottingLibrary(object): """ raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library") - def show_canvas(self, canvas, plots, xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, **kwargs): + def show_canvas(self, canvas, plots, xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, legend=True, **kwargs): """ Show the canvas given. plots is a dictionary with the plots diff --git a/GPy/plotting/matplot_dep/plot_definitions.py b/GPy/plotting/matplot_dep/plot_definitions.py index 598482d3..4d838722 100644 --- a/GPy/plotting/matplot_dep/plot_definitions.py +++ b/GPy/plotting/matplot_dep/plot_definitions.py @@ -42,7 +42,12 @@ class MatplotlibPlots(AbstractPlottingLibrary): super(MatplotlibPlots, self).__init__() self._defaults = defaults.__dict__ - def get_new_canvas(self, projection='2d', **kwargs): + def figure(self, rows=1, cols=1, **kwargs): + self.rows = rows + self.cols = cols + return plt.figure(**kwargs) + + def get_new_canvas(self, projection='2d', figure=None, col=1, row=1, **kwargs): if projection == '3d': from mpl_toolkits.mplot3d import Axes3D elif projection == '2d': @@ -50,13 +55,13 @@ class MatplotlibPlots(AbstractPlottingLibrary): if 'ax' in kwargs: ax = kwargs.pop('ax') elif 'num' in kwargs and 'figsize' in kwargs: - ax = plt.figure(num=kwargs.pop('num'), figsize=kwargs.pop('figsize')).add_subplot(rows, cols, which, projection=projection) + fig = self.figure(num=kwargs.pop('num'), figsize=kwargs.pop('figsize')).add_subplot(111, projection=projection) elif 'num' in kwargs: - ax = plt.figure(num=kwargs.pop('num')).add_subplot(111, projection=projection) + ax = self.figure(num=kwargs.pop('num')).add_subplot(111, projection=projection) elif 'figsize' in kwargs: - ax = plt.figure(figsize=kwargs.pop('figsize')).add_subplot(111, projection=projection) + ax = self.figure(figsize=kwargs.pop('figsize')).add_subplot(111, projection=projection) else: - ax = plt.figure().add_subplot(111, projection=projection) + ax = self.figure().add_subplot(111, projection=projection) return ax, kwargs diff --git a/travis_tests.py b/travis_tests.py index 2d71de97..06d54de6 100644 --- a/travis_tests.py +++ b/travis_tests.py @@ -38,5 +38,5 @@ matplotlib.rcParams[u'figure.figsize'] = (4,3) matplotlib.rcParams[u'text.usetex'] = False import nose -nose.main('GPy', defaultTest='GPy/testing/plotting_tests.py') +nose.main('GPy', defaultTest='GPy/testing')