diff --git a/.travis.yml b/.travis.yml index 35d31f2b..f470f05c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,6 +67,6 @@ deploy: on: #tags: true branch: plot_density - #server: https://testpypi.python.org/pypi + server: https://testpypi.python.org/pypi distributions: "bdist_wheel sdist" skip_cleanup: true diff --git a/GPy/__version__.py b/GPy/__version__.py index 21311fc4..01fef660 100644 --- a/GPy/__version__.py +++ b/GPy/__version__.py @@ -1 +1 @@ -__version__ = "0.8.8dev0" +__version__ = "0.8.8dev2" diff --git a/GPy/plotting/__init__.py b/GPy/plotting/__init__.py index 8f82720e..28c05cef 100644 --- a/GPy/plotting/__init__.py +++ b/GPy/plotting/__init__.py @@ -84,6 +84,11 @@ if config.get('plotting', 'library') is not 'none': from ..kern import Kern Kern.plot_covariance = gpy_plot.kernel_plots.plot_covariance + def deprecate_plot(self, *args, **kwargs): + import warnings + warnings.warn(DeprecationWarning('Kern.plot is being deprecated and will not be available in the 1.0 release. Use Kern.plot_covariance instead')) + return self.plot_covariance(*args, **kwargs) + Kern.plot = deprecate_plot Kern.plot_ARD = gpy_plot.kernel_plots.plot_ARD from ..inference.optimization import Optimizer diff --git a/GPy/plotting/gpy_plot/kernel_plots.py b/GPy/plotting/gpy_plot/kernel_plots.py index daae15b8..01796d84 100644 --- a/GPy/plotting/gpy_plot/kernel_plots.py +++ b/GPy/plotting/gpy_plot/kernel_plots.py @@ -136,6 +136,4 @@ def plot_covariance(kernel, x=None, label=None, return pl().add_to_canvas(canvas, plots) else: - raise NotImplementedError("Cannot plot a kernel with more than two input dimensions") - - pass \ No newline at end of file + raise NotImplementedError("Cannot plot a kernel with more than two input dimensions") \ No newline at end of file diff --git a/doc/source/tuto_plotting.rst b/doc/source/tuto_plotting.rst index adf00b66..8da53135 100644 --- a/doc/source/tuto_plotting.rst +++ b/doc/source/tuto_plotting.rst @@ -89,3 +89,57 @@ meanplot_1d, which we are for the 1d plot:: The full definition of the plotting then looks like this:: + if len(free_dims)<=2: + if len(free_dims)==1: + # 1D plotting: + update_not_existing_kwargs(kwargs, pl().defaults.meanplot_1d) # @UndefinedVariable + plots = dict(covariance=[pl().plot(canvas, Xgrid[:, free_dims], K, label=label, **kwargs)]) + else: + if projection == '2d': + update_not_existing_kwargs(kwargs, pl().defaults.meanplot_2d) # @UndefinedVariable + plots = dict(covariance=[pl().contour(canvas, xx[:, 0], yy[0, :], + K.reshape(resolution, resolution), + levels=levels, label=label, **kwargs)]) + elif projection == '3d': + update_not_existing_kwargs(kwargs, pl().defaults.meanplot_3d) # @UndefinedVariable + plots = dict(covariance=[pl().surface(canvas, xx, yy, + K.reshape(resolution, resolution), + label=label, + **kwargs)]) + return pl().add_to_canvas(canvas, plots) + + else: + raise NotImplementedError("Cannot plot a kernel with more than two input dimensions") + +Where we return whatever is returned by :py:func:`GPy.plotting.abstract_plotting_library.AbstractPlottingLibrary.add_to_canvas`, +so that the plotting library can choose what to do with the plot later, when we want to show it. In order +to show a plot, we can just call :py:func:`GPy.plotting.show` with the output of the plot above. + +Now we want to add the plot to the :py:class:`GPy.kern.src.kern.Kern`. In order to do that, we inject the plotting function into the +class in the :py:mod:`GPy.plotting.__init__`, which will make sure that the on the fly change of the backend +works smoothly. Thus, in :py:mod:`GPy.plotting.__init__` we add the line:: + + from ..kern import Kern + Kern.plot_covariance = gpy_plot.kernel_plots.plot_covariance + +And that's it. The plot can be shown in plotly by calling:: + + GPy.plotting.change_plotting_library('plotly') + + k = GPy.kern.RBF(1) + GPy.kern.Matern32(1) + k.randomize() + fig = k.plot() + GPy.plotting.show(fig, ) + + k = GPy.kern.RBF(2) + GPy.kern.Matern32(2) + k.randomize() + fig = k.plot() + GPy.plotting.show(fig, ) + + k = GPy.kern.RBF(1) + GPy.kern.Matern32(2) + k.randomize() + fig = k.plot(projection='3d') + GPy.plotting.show(fig, ) + +This explains the next thing. Changing the backend works *on-the-fly*. To show the above example in matplotlib, we just +exchange the first line by ``GPy.plotting.change_plotting_library('matplotlib')``. diff --git a/setup.cfg b/setup.cfg index d79d8bbd..35cc840c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.8.8dev0 +current_version = 0.8.8dev2 tag = True commit = True