diff --git a/GPy/likelihoods/likelihood.py b/GPy/likelihoods/likelihood.py index b4f72719..bd84b72c 100644 --- a/GPy/likelihoods/likelihood.py +++ b/GPy/likelihoods/likelihood.py @@ -296,7 +296,7 @@ class Likelihood(Parameterized): elif quad_mode == 'gh': f = partial(self.integrate_gh) quads = zip(*map(f, Y.flatten(), mu.flatten(), np.sqrt(sigma2.flatten()))) - quads = np.hstack(quads) + quads = np.hstack(list(quads)) quads = quads.T else: raise Exception("no other quadrature mode available") diff --git a/GPy/plotting/matplot_dep/base_plots.py b/GPy/plotting/matplot_dep/base_plots.py index d9910f59..567f869b 100644 --- a/GPy/plotting/matplot_dep/base_plots.py +++ b/GPy/plotting/matplot_dep/base_plots.py @@ -3,6 +3,8 @@ from matplotlib import pyplot as plt import numpy as np +from .util import align_subplot_array, align_subplots + def ax_default(fignum, ax): if ax is None: fig = plt.figure(fignum) @@ -50,73 +52,73 @@ def gradient_fill(x, percentiles, ax=None, fignum=None, **kwargs): kwargs['linewidth'] = 0.5 if not 'alpha' in kwargs.keys(): kwargs['alpha'] = 1./(len(percentiles)) - + # pop where from kwargs where = kwargs.pop('where') if 'where' in kwargs else None # pop interpolate, which we actually do not do here! if 'interpolate' in kwargs: kwargs.pop('interpolate') - + def pairwise(inlist): l = len(inlist) for i in range(int(np.ceil(l/2.))): yield inlist[:][i], inlist[:][(l-1)-i] - + polycol = [] for y1, y2 in pairwise(percentiles): import matplotlib.mlab as mlab # Handle united data, such as dates ax._process_unit_info(xdata=x, ydata=y1) ax._process_unit_info(ydata=y2) - + # Convert the arrays so we can work with them from numpy import ma x = ma.masked_invalid(ax.convert_xunits(x)) y1 = ma.masked_invalid(ax.convert_yunits(y1)) y2 = ma.masked_invalid(ax.convert_yunits(y2)) - + if y1.ndim == 0: y1 = np.ones_like(x) * y1 if y2.ndim == 0: y2 = np.ones_like(x) * y2 - + if where is None: where = np.ones(len(x), np.bool) else: where = np.asarray(where, np.bool) - + if not (x.shape == y1.shape == y2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - + mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)]) if mask is not ma.nomask: where &= ~mask - + polys = [] for ind0, ind1 in mlab.contiguous_regions(where): xslice = x[ind0:ind1] y1slice = y1[ind0:ind1] y2slice = y2[ind0:ind1] - + if not len(xslice): continue - + N = len(xslice) X = np.zeros((2 * N + 2, 2), np.float) - + # the purpose of the next two lines is for when y2 is a # scalar like 0 and we want the fill to go all the way # down to 0 even if none of the y1 sample points do start = xslice[0], y2slice[0] end = xslice[-1], y2slice[-1] - + X[0] = start X[N + 1] = end - + X[1:N + 1, 0] = xslice X[1:N + 1, 1] = y1slice X[N + 2:, 0] = xslice[::-1] X[N + 2:, 1] = y2slice[::-1] - + polys.append(X) polycol.extend(polys) from matplotlib.collections import PolyCollection @@ -167,65 +169,6 @@ def fewerXticks(ax=None,divideby=2): ax = ax or plt.gca() ax.set_xticks(ax.get_xticks()[::divideby]) -def align_subplots(N,M,xlim=None, ylim=None): - """make all of the subplots have the same limits, turn off unnecessary ticks""" - #find sensible xlim,ylim - if xlim is None: - xlim = [np.inf,-np.inf] - for i in range(N*M): - plt.subplot(N,M,i+1) - xlim[0] = min(xlim[0],plt.xlim()[0]) - xlim[1] = max(xlim[1],plt.xlim()[1]) - if ylim is None: - ylim = [np.inf,-np.inf] - for i in range(N*M): - plt.subplot(N,M,i+1) - ylim[0] = min(ylim[0],plt.ylim()[0]) - ylim[1] = max(ylim[1],plt.ylim()[1]) - - for i in range(N*M): - plt.subplot(N,M,i+1) - plt.xlim(xlim) - plt.ylim(ylim) - if (i)%M: - plt.yticks([]) - else: - removeRightTicks() - if i<(M*(N-1)): - plt.xticks([]) - else: - removeUpperTicks() - -def align_subplot_array(axes,xlim=None, ylim=None): - """ - Make all of the axes in the array hae the same limits, turn off unnecessary ticks - use plt.subplots() to get an array of axes - """ - #find sensible xlim,ylim - if xlim is None: - xlim = [np.inf,-np.inf] - for ax in axes.flatten(): - xlim[0] = min(xlim[0],ax.get_xlim()[0]) - xlim[1] = max(xlim[1],ax.get_xlim()[1]) - if ylim is None: - ylim = [np.inf,-np.inf] - for ax in axes.flatten(): - ylim[0] = min(ylim[0],ax.get_ylim()[0]) - ylim[1] = max(ylim[1],ax.get_ylim()[1]) - - N,M = axes.shape - for i,ax in enumerate(axes.flatten()): - ax.set_xlim(xlim) - ax.set_ylim(ylim) - if (i)%M: - ax.set_yticks([]) - else: - removeRightTicks(ax) - if i<(M*(N-1)): - ax.set_xticks([]) - else: - removeUpperTicks(ax) - def x_frame1D(X,plot_limits=None,resolution=None): """ Internal helper function for making plots, returns a set of input values to plot as well as lower and upper limits diff --git a/GPy/testing/baseline/bayesian_gplvm_gradient.npz b/GPy/testing/baseline/bayesian_gplvm_gradient.npz deleted file mode 100644 index 1aca64d4..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_gradient.npz and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_inducing.npz b/GPy/testing/baseline/bayesian_gplvm_inducing.npz deleted file mode 100644 index 01030a19..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_inducing.npz and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_inducing_3d.npz b/GPy/testing/baseline/bayesian_gplvm_inducing_3d.npz deleted file mode 100644 index cdd06e7a..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_inducing_3d.npz and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_latent.npz b/GPy/testing/baseline/bayesian_gplvm_latent.npz deleted file mode 100644 index 2e19707c..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_latent.npz and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_latent_3d.npz b/GPy/testing/baseline/bayesian_gplvm_latent_3d.npz deleted file mode 100644 index 3424eeb1..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_latent_3d.npz and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_magnification.npz b/GPy/testing/baseline/bayesian_gplvm_magnification.npz deleted file mode 100644 index 0aec4d87..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_magnification.npz and /dev/null differ diff --git a/GPy/testing/baseline/coverage_3d_plot.npz b/GPy/testing/baseline/coverage_3d_plot.npz index 99958e70..2f974bcd 100644 Binary files a/GPy/testing/baseline/coverage_3d_plot.npz and b/GPy/testing/baseline/coverage_3d_plot.npz differ diff --git a/GPy/testing/baseline/coverage_annotation_interact.npz b/GPy/testing/baseline/coverage_annotation_interact.npz index 2f974bcd..114cc334 100644 Binary files a/GPy/testing/baseline/coverage_annotation_interact.npz and b/GPy/testing/baseline/coverage_annotation_interact.npz differ diff --git a/GPy/testing/baseline/coverage_gradient.npz b/GPy/testing/baseline/coverage_gradient.npz index b30ed37e..b9e01e67 100644 Binary files a/GPy/testing/baseline/coverage_gradient.npz and b/GPy/testing/baseline/coverage_gradient.npz differ diff --git a/GPy/testing/baseline/coverage_imshow_interact.npz b/GPy/testing/baseline/coverage_imshow_interact.npz index b9e01e67..28e5cdfa 100644 Binary files a/GPy/testing/baseline/coverage_imshow_interact.npz and b/GPy/testing/baseline/coverage_imshow_interact.npz differ diff --git a/GPy/testing/baseline/gp_2d_mean.npz b/GPy/testing/baseline/gp_2d_mean.npz index 86a72f61..de291d50 100644 Binary files a/GPy/testing/baseline/gp_2d_mean.npz and b/GPy/testing/baseline/gp_2d_mean.npz differ diff --git a/GPy/testing/baseline/gp_3d_data.npz b/GPy/testing/baseline/gp_3d_data.npz deleted file mode 100644 index 0c6e7bed..00000000 Binary files a/GPy/testing/baseline/gp_3d_data.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_3d_inducing.npz b/GPy/testing/baseline/gp_3d_inducing.npz deleted file mode 100644 index 082062d3..00000000 Binary files a/GPy/testing/baseline/gp_3d_inducing.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_3d_mean.npz b/GPy/testing/baseline/gp_3d_mean.npz deleted file mode 100644 index abc4a951..00000000 Binary files a/GPy/testing/baseline/gp_3d_mean.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_likelihood.npz b/GPy/testing/baseline/gp_class_likelihood.npz deleted file mode 100644 index 779ec008..00000000 Binary files a/GPy/testing/baseline/gp_class_likelihood.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_raw.npz b/GPy/testing/baseline/gp_class_raw.npz deleted file mode 100644 index e85c9103..00000000 Binary files a/GPy/testing/baseline/gp_class_raw.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_raw_link.npz b/GPy/testing/baseline/gp_class_raw_link.npz deleted file mode 100644 index c4e876fe..00000000 Binary files a/GPy/testing/baseline/gp_class_raw_link.npz and /dev/null differ diff --git a/GPy/testing/baseline/gp_samples.npz b/GPy/testing/baseline/gp_samples.npz index f47b14f8..1d6fa101 100644 Binary files a/GPy/testing/baseline/gp_samples.npz and b/GPy/testing/baseline/gp_samples.npz differ diff --git a/GPy/testing/baseline/gplvm_gradient.npz b/GPy/testing/baseline/gplvm_gradient.npz deleted file mode 100644 index 8e7fce34..00000000 Binary files a/GPy/testing/baseline/gplvm_gradient.npz and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_latent.npz b/GPy/testing/baseline/gplvm_latent.npz deleted file mode 100644 index ebf171e2..00000000 Binary files a/GPy/testing/baseline/gplvm_latent.npz and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_latent_3d.npz b/GPy/testing/baseline/gplvm_latent_3d.npz deleted file mode 100644 index 2ad0dfc2..00000000 Binary files a/GPy/testing/baseline/gplvm_latent_3d.npz and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_magnification.npz b/GPy/testing/baseline/gplvm_magnification.npz deleted file mode 100644 index 0d1ac512..00000000 Binary files a/GPy/testing/baseline/gplvm_magnification.npz and /dev/null differ diff --git a/GPy/testing/baseline/kern_cov_2d.npz b/GPy/testing/baseline/kern_cov_2d.npz index 51ee481c..4b82fa05 100644 Binary files a/GPy/testing/baseline/kern_cov_2d.npz and b/GPy/testing/baseline/kern_cov_2d.npz differ diff --git a/GPy/testing/baseline/kern_cov_3d.npz b/GPy/testing/baseline/kern_cov_3d.npz index a631b730..b8b57761 100644 Binary files a/GPy/testing/baseline/kern_cov_3d.npz and b/GPy/testing/baseline/kern_cov_3d.npz differ diff --git a/GPy/testing/baseline/kern_cov_no_lim.npz b/GPy/testing/baseline/kern_cov_no_lim.npz index 1f399330..a049482b 100644 Binary files a/GPy/testing/baseline/kern_cov_no_lim.npz and b/GPy/testing/baseline/kern_cov_no_lim.npz differ diff --git a/GPy/testing/baseline/sparse_gp_class_likelihood.npz b/GPy/testing/baseline/sparse_gp_class_likelihood.npz deleted file mode 100644 index 9661f3bb..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_likelihood.npz and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_class_raw.npz b/GPy/testing/baseline/sparse_gp_class_raw.npz deleted file mode 100644 index 1b730c35..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_raw.npz and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_class_raw_link.npz b/GPy/testing/baseline/sparse_gp_class_raw_link.npz deleted file mode 100644 index aa4ccda5..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_raw_link.npz and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_data_error.npz b/GPy/testing/baseline/sparse_gp_data_error.npz deleted file mode 100644 index 6e1430b8..00000000 Binary files a/GPy/testing/baseline/sparse_gp_data_error.npz and /dev/null differ diff --git a/GPy/testing/plotting_tests.py b/GPy/testing/plotting_tests.py index b5ae0037..1e9cb6c5 100644 --- a/GPy/testing/plotting_tests.py +++ b/GPy/testing/plotting_tests.py @@ -38,7 +38,7 @@ from nose import SkipTest try: import matplotlib - # matplotlib.use('agg') + matplotlib.use('agg', warn=False) except ImportError: # matplotlib not installed from nose import SkipTest @@ -48,6 +48,7 @@ from unittest.case import TestCase import numpy as np import GPy, os +import logging from GPy.util.config import config from GPy.plotting import change_plotting_library, plotting_library @@ -98,18 +99,26 @@ def _image_comparison(baseline_images, extensions=['pdf','svg','png'], tol=11, r for num, base in zip(plt.get_fignums(), baseline_images): for ext in extensions: fig = plt.figure(num) - fig.canvas.draw() + try: + fig.canvas.draw() + except Exception as e: + logging.error(base) + raise SkipTest(e) #fig.axes[0].set_axis_off() #fig.set_frameon(False) if ext in ['npz']: figdict = flatten_axis(fig) np.savez_compressed(os.path.join(result_dir, "{}.{}".format(base, ext)), **figdict) - fig.savefig(os.path.join(result_dir, "{}.{}".format(base, 'png')), - transparent=True, - edgecolor='none', - facecolor='none', - #bbox='tight' - ) + try: + fig.savefig(os.path.join(result_dir, "{}.{}".format(base, 'png')), + transparent=True, + edgecolor='none', + facecolor='none', + #bbox='tight' + ) + except: + logging.error(base) + raise else: fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)), transparent=True, diff --git a/travis_tests.py b/travis_tests.py index 16713962..bd3f5680 100644 --- a/travis_tests.py +++ b/travis_tests.py @@ -31,7 +31,7 @@ #!/usr/bin/env python import matplotlib -matplotlib.use('agg') +matplotlib.use('agg', warn=False) import nose, warnings with warnings.catch_warnings():