[tests] now working?

This commit is contained in:
mzwiessele 2015-10-07 01:39:14 +01:00
parent 94e8f47e3e
commit 7d90630c1b
3 changed files with 23 additions and 8 deletions

View file

@ -57,9 +57,19 @@ class AbstractPlottingLibrary(object):
return self.__defaults 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. 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 This method does two things, it creates an empty canvas
and updates the kwargs (deletes the unnecessary kwargs) 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") 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. Show the canvas given.
plots is a dictionary with the plots plots is a dictionary with the plots

View file

@ -42,7 +42,12 @@ class MatplotlibPlots(AbstractPlottingLibrary):
super(MatplotlibPlots, self).__init__() super(MatplotlibPlots, self).__init__()
self._defaults = defaults.__dict__ 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': if projection == '3d':
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
elif projection == '2d': elif projection == '2d':
@ -50,13 +55,13 @@ class MatplotlibPlots(AbstractPlottingLibrary):
if 'ax' in kwargs: if 'ax' in kwargs:
ax = kwargs.pop('ax') ax = kwargs.pop('ax')
elif 'num' in kwargs and 'figsize' in kwargs: 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: 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: 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: else:
ax = plt.figure().add_subplot(111, projection=projection) ax = self.figure().add_subplot(111, projection=projection)
return ax, kwargs return ax, kwargs

View file

@ -38,5 +38,5 @@ matplotlib.rcParams[u'figure.figsize'] = (4,3)
matplotlib.rcParams[u'text.usetex'] = False matplotlib.rcParams[u'text.usetex'] = False
import nose import nose
nose.main('GPy', defaultTest='GPy/testing/plotting_tests.py') nose.main('GPy', defaultTest='GPy/testing')