diff --git a/GPy/plotting/gpy_plot/latent_plots.py b/GPy/plotting/gpy_plot/latent_plots.py index f522d297..49e93382 100644 --- a/GPy/plotting/gpy_plot/latent_plots.py +++ b/GPy/plotting/gpy_plot/latent_plots.py @@ -112,7 +112,7 @@ def plot_latent_inducing(self, which_indices=None, legend=False, plot_limits=None, - marker='^', + marker=None, num_samples=1000, projection='2d', **kwargs): @@ -124,16 +124,18 @@ def plot_latent_inducing(self, :param bool legend: whether to plot the legend on the figure :param plot_limits: the plot limits for the plot :type plot_limits: (xmin, xmax, ymin, ymax) or ((xmin, xmax), (ymin, ymax)) - :param str marker: markers to use - cycle if more labels then markers are given + :param str marker: marker to use [default is custom arrow like] :param kwargs: the kwargs for the scatter plots """ canvas, projection, kwargs, sig_dims = _new_canvas(self, projection, kwargs, which_indices) - Z = self.Z.values - labels = np.array(['inducing'] * Z.shape[0]) - kwargs['marker'] = marker + if legend: label = 'inducing' + else: label = None + if marker is not None: + kwargs['marker'] = marker update_not_existing_kwargs(kwargs, pl().defaults.inducing_2d) # @UndefinedVariable - scatters = _plot_latent_scatter(canvas, Z, sig_dims, labels, num_samples=num_samples, projection=projection, **kwargs) + from .data_plots import _plot_inducing + scatters = _plot_inducing(self, canvas, sig_dims[:2], projection, label, num_samples=num_samples, **kwargs) return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend) diff --git a/GPy/plotting/matplot_dep/defaults.py b/GPy/plotting/matplot_dep/defaults.py index 38b08dd1..8518b9d0 100644 --- a/GPy/plotting/matplot_dep/defaults.py +++ b/GPy/plotting/matplot_dep/defaults.py @@ -45,7 +45,7 @@ it gives back an empty default, when defaults are not defined. # Data plots: data_1d = dict(lw=1.5, marker='x', color='k') data_2d = dict(s=35, edgecolors='none', linewidth=0., cmap=cm.get_cmap('hot'), alpha=.5) -inducing_1d = dict(lw=0, s=500, facecolors=Tango.colorsHex['darkRed']) +inducing_1d = dict(lw=0, s=500, color=Tango.colorsHex['darkRed']) inducing_2d = dict(s=17, edgecolor='k', linewidth=.4, color='white', alpha=.5, marker='^') inducing_3d = dict(lw=.3, s=500, color=Tango.colorsHex['darkRed'], edgecolor='k') xerrorbar = dict(color='k', fmt='none', elinewidth=.5, alpha=.5) diff --git a/GPy/plotting/matplot_dep/plot_definitions.py b/GPy/plotting/matplot_dep/plot_definitions.py index 52100ea3..0e3bc32d 100644 --- a/GPy/plotting/matplot_dep/plot_definitions.py +++ b/GPy/plotting/matplot_dep/plot_definitions.py @@ -106,7 +106,7 @@ class MatplotlibPlots(AbstractPlottingLibrary): return ax.plot(X, Y, color=color, zs=Z, label=label, **kwargs) return ax.plot(X, Y, color=color, label=label, **kwargs) - def plot_axis_lines(self, ax, X, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs): + def plot_axis_lines(self, ax, X, color=Tango.colorsHex['darkRed'], label=None, **kwargs): from matplotlib import transforms from matplotlib.path import Path if 'marker' not in kwargs: @@ -126,14 +126,14 @@ class MatplotlibPlots(AbstractPlottingLibrary): bottom=bottom, label=label, color=color, **kwargs) - def xerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs): + def xerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['darkRed'], label=None, **kwargs): if not('linestyle' in kwargs or 'ls' in kwargs): kwargs['ls'] = 'none' #if Z is not None: # return ax.errorbar(X, Y, Z, xerr=error, ecolor=color, label=label, **kwargs) return ax.errorbar(X, Y, xerr=error, ecolor=color, label=label, **kwargs) - def yerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs): + def yerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['darkRed'], label=None, **kwargs): if not('linestyle' in kwargs or 'ls' in kwargs): kwargs['ls'] = 'none' #if Z is not None: diff --git a/GPy/testing/baseline/bayesian_gplvm_gradient.png b/GPy/testing/baseline/bayesian_gplvm_gradient.png deleted file mode 100644 index e607caad..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_gradient.png and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_inducing.png b/GPy/testing/baseline/bayesian_gplvm_inducing.png deleted file mode 100644 index dd7e66f2..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_inducing.png and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_inducing_3d.png b/GPy/testing/baseline/bayesian_gplvm_inducing_3d.png deleted file mode 100644 index ae541f2e..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_inducing_3d.png and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_latent.png b/GPy/testing/baseline/bayesian_gplvm_latent.png deleted file mode 100644 index 85c17a6e..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_latent.png and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_latent_3d.png b/GPy/testing/baseline/bayesian_gplvm_latent_3d.png deleted file mode 100644 index 1bba1b64..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_latent_3d.png and /dev/null differ diff --git a/GPy/testing/baseline/bayesian_gplvm_magnification.png b/GPy/testing/baseline/bayesian_gplvm_magnification.png deleted file mode 100644 index 4777e89f..00000000 Binary files a/GPy/testing/baseline/bayesian_gplvm_magnification.png and /dev/null differ diff --git a/GPy/testing/baseline/coverage_3d_plot.npz b/GPy/testing/baseline/coverage_3d_plot.npz new file mode 100644 index 00000000..b8bf090c Binary files /dev/null and b/GPy/testing/baseline/coverage_3d_plot.npz differ diff --git a/GPy/testing/baseline/coverage_3d_plot.png b/GPy/testing/baseline/coverage_3d_plot.png deleted file mode 100644 index 43f165e6..00000000 Binary files a/GPy/testing/baseline/coverage_3d_plot.png and /dev/null differ diff --git a/GPy/testing/baseline/coverage_annotation_interact.npz b/GPy/testing/baseline/coverage_annotation_interact.npz new file mode 100644 index 00000000..61cab600 Binary files /dev/null and b/GPy/testing/baseline/coverage_annotation_interact.npz differ diff --git a/GPy/testing/baseline/coverage_annotation_interact.png b/GPy/testing/baseline/coverage_annotation_interact.png deleted file mode 100644 index f51d20d2..00000000 Binary files a/GPy/testing/baseline/coverage_annotation_interact.png and /dev/null differ diff --git a/GPy/testing/baseline/coverage_gradient.npz b/GPy/testing/baseline/coverage_gradient.npz new file mode 100644 index 00000000..093d563d Binary files /dev/null and b/GPy/testing/baseline/coverage_gradient.npz differ diff --git a/GPy/testing/baseline/coverage_gradient.png b/GPy/testing/baseline/coverage_gradient.png deleted file mode 100644 index aa4b6718..00000000 Binary files a/GPy/testing/baseline/coverage_gradient.png and /dev/null differ diff --git a/GPy/testing/baseline/coverage_imshow_interact.npz b/GPy/testing/baseline/coverage_imshow_interact.npz new file mode 100644 index 00000000..6679b8b2 Binary files /dev/null and b/GPy/testing/baseline/coverage_imshow_interact.npz differ diff --git a/GPy/testing/baseline/coverage_imshow_interact.png b/GPy/testing/baseline/coverage_imshow_interact.png deleted file mode 100644 index 879bfcef..00000000 Binary files a/GPy/testing/baseline/coverage_imshow_interact.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_2d_data.npz b/GPy/testing/baseline/gp_2d_data.npz new file mode 100644 index 00000000..154a3716 Binary files /dev/null and b/GPy/testing/baseline/gp_2d_data.npz differ diff --git a/GPy/testing/baseline/gp_2d_data.png b/GPy/testing/baseline/gp_2d_data.png deleted file mode 100644 index 7c8cf204..00000000 Binary files a/GPy/testing/baseline/gp_2d_data.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_2d_in_error.npz b/GPy/testing/baseline/gp_2d_in_error.npz new file mode 100644 index 00000000..a34e06ab Binary files /dev/null and b/GPy/testing/baseline/gp_2d_in_error.npz differ diff --git a/GPy/testing/baseline/gp_2d_in_error.png b/GPy/testing/baseline/gp_2d_in_error.png deleted file mode 100644 index b3168e7c..00000000 Binary files a/GPy/testing/baseline/gp_2d_in_error.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_2d_inducing.npz b/GPy/testing/baseline/gp_2d_inducing.npz new file mode 100644 index 00000000..4848056c Binary files /dev/null and b/GPy/testing/baseline/gp_2d_inducing.npz differ diff --git a/GPy/testing/baseline/gp_2d_inducing.png b/GPy/testing/baseline/gp_2d_inducing.png deleted file mode 100644 index f669c9af..00000000 Binary files a/GPy/testing/baseline/gp_2d_inducing.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_2d_mean.npz b/GPy/testing/baseline/gp_2d_mean.npz new file mode 100644 index 00000000..615a962c Binary files /dev/null and b/GPy/testing/baseline/gp_2d_mean.npz differ diff --git a/GPy/testing/baseline/gp_2d_mean.png b/GPy/testing/baseline/gp_2d_mean.png deleted file mode 100644 index 02fb271f..00000000 Binary files a/GPy/testing/baseline/gp_2d_mean.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_3d_data.npz b/GPy/testing/baseline/gp_3d_data.npz new file mode 100644 index 00000000..e7d61a0e Binary files /dev/null and b/GPy/testing/baseline/gp_3d_data.npz differ diff --git a/GPy/testing/baseline/gp_3d_data.png b/GPy/testing/baseline/gp_3d_data.png deleted file mode 100644 index 45e3ca49..00000000 Binary files a/GPy/testing/baseline/gp_3d_data.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_3d_inducing.npz b/GPy/testing/baseline/gp_3d_inducing.npz new file mode 100644 index 00000000..c1d0d121 Binary files /dev/null and b/GPy/testing/baseline/gp_3d_inducing.npz differ diff --git a/GPy/testing/baseline/gp_3d_inducing.png b/GPy/testing/baseline/gp_3d_inducing.png deleted file mode 100644 index 35dada70..00000000 Binary files a/GPy/testing/baseline/gp_3d_inducing.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_3d_mean.npz b/GPy/testing/baseline/gp_3d_mean.npz new file mode 100644 index 00000000..bbb5c150 Binary files /dev/null and b/GPy/testing/baseline/gp_3d_mean.npz differ diff --git a/GPy/testing/baseline/gp_3d_mean.png b/GPy/testing/baseline/gp_3d_mean.png deleted file mode 100644 index 5433934d..00000000 Binary files a/GPy/testing/baseline/gp_3d_mean.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_likelihood.npz b/GPy/testing/baseline/gp_class_likelihood.npz new file mode 100644 index 00000000..d9ec94a2 Binary files /dev/null and b/GPy/testing/baseline/gp_class_likelihood.npz differ diff --git a/GPy/testing/baseline/gp_class_likelihood.png b/GPy/testing/baseline/gp_class_likelihood.png deleted file mode 100644 index d99a004f..00000000 Binary files a/GPy/testing/baseline/gp_class_likelihood.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_raw.npz b/GPy/testing/baseline/gp_class_raw.npz new file mode 100644 index 00000000..76cda217 Binary files /dev/null and b/GPy/testing/baseline/gp_class_raw.npz differ diff --git a/GPy/testing/baseline/gp_class_raw.png b/GPy/testing/baseline/gp_class_raw.png deleted file mode 100644 index 1d6990e0..00000000 Binary files a/GPy/testing/baseline/gp_class_raw.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_class_raw_link.npz b/GPy/testing/baseline/gp_class_raw_link.npz new file mode 100644 index 00000000..ade76e23 Binary files /dev/null and b/GPy/testing/baseline/gp_class_raw_link.npz differ diff --git a/GPy/testing/baseline/gp_class_raw_link.png b/GPy/testing/baseline/gp_class_raw_link.png deleted file mode 100644 index 9c207acd..00000000 Binary files a/GPy/testing/baseline/gp_class_raw_link.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_conf.npz b/GPy/testing/baseline/gp_conf.npz new file mode 100644 index 00000000..7b5411e6 Binary files /dev/null and b/GPy/testing/baseline/gp_conf.npz differ diff --git a/GPy/testing/baseline/gp_conf.png b/GPy/testing/baseline/gp_conf.png deleted file mode 100644 index 13885af3..00000000 Binary files a/GPy/testing/baseline/gp_conf.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_data.npz b/GPy/testing/baseline/gp_data.npz new file mode 100644 index 00000000..b1048dab Binary files /dev/null and b/GPy/testing/baseline/gp_data.npz differ diff --git a/GPy/testing/baseline/gp_data.png b/GPy/testing/baseline/gp_data.png deleted file mode 100644 index 780fe389..00000000 Binary files a/GPy/testing/baseline/gp_data.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_density.npz b/GPy/testing/baseline/gp_density.npz new file mode 100644 index 00000000..76f41cd9 Binary files /dev/null and b/GPy/testing/baseline/gp_density.npz differ diff --git a/GPy/testing/baseline/gp_density.png b/GPy/testing/baseline/gp_density.png deleted file mode 100644 index 34d4c925..00000000 Binary files a/GPy/testing/baseline/gp_density.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_in_error.npz b/GPy/testing/baseline/gp_in_error.npz new file mode 100644 index 00000000..250b5aaf Binary files /dev/null and b/GPy/testing/baseline/gp_in_error.npz differ diff --git a/GPy/testing/baseline/gp_in_error.png b/GPy/testing/baseline/gp_in_error.png deleted file mode 100644 index 8c8d13de..00000000 Binary files a/GPy/testing/baseline/gp_in_error.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_mean.npz b/GPy/testing/baseline/gp_mean.npz new file mode 100644 index 00000000..c5052134 Binary files /dev/null and b/GPy/testing/baseline/gp_mean.npz differ diff --git a/GPy/testing/baseline/gp_mean.png b/GPy/testing/baseline/gp_mean.png deleted file mode 100644 index b1019869..00000000 Binary files a/GPy/testing/baseline/gp_mean.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_out_error.npz b/GPy/testing/baseline/gp_out_error.npz new file mode 100644 index 00000000..f84851a6 Binary files /dev/null and b/GPy/testing/baseline/gp_out_error.npz differ diff --git a/GPy/testing/baseline/gp_out_error.png b/GPy/testing/baseline/gp_out_error.png deleted file mode 100644 index 696786f4..00000000 Binary files a/GPy/testing/baseline/gp_out_error.png and /dev/null differ diff --git a/GPy/testing/baseline/gp_samples.npz b/GPy/testing/baseline/gp_samples.npz new file mode 100644 index 00000000..059abcb4 Binary files /dev/null and b/GPy/testing/baseline/gp_samples.npz differ diff --git a/GPy/testing/baseline/gp_samples.png b/GPy/testing/baseline/gp_samples.png deleted file mode 100644 index 95dbd4ff..00000000 Binary files a/GPy/testing/baseline/gp_samples.png and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_gradient.npz b/GPy/testing/baseline/gplvm_gradient.npz new file mode 100644 index 00000000..c2521a94 Binary files /dev/null and b/GPy/testing/baseline/gplvm_gradient.npz differ diff --git a/GPy/testing/baseline/gplvm_gradient.png b/GPy/testing/baseline/gplvm_gradient.png deleted file mode 100644 index d3d0dc72..00000000 Binary files a/GPy/testing/baseline/gplvm_gradient.png and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_latent.npz b/GPy/testing/baseline/gplvm_latent.npz new file mode 100644 index 00000000..4a266b02 Binary files /dev/null and b/GPy/testing/baseline/gplvm_latent.npz differ diff --git a/GPy/testing/baseline/gplvm_latent.png b/GPy/testing/baseline/gplvm_latent.png deleted file mode 100644 index 5d3c92ae..00000000 Binary files a/GPy/testing/baseline/gplvm_latent.png and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_latent_3d.npz b/GPy/testing/baseline/gplvm_latent_3d.npz new file mode 100644 index 00000000..60a153b8 Binary files /dev/null and b/GPy/testing/baseline/gplvm_latent_3d.npz differ diff --git a/GPy/testing/baseline/gplvm_latent_3d.png b/GPy/testing/baseline/gplvm_latent_3d.png deleted file mode 100644 index 1bba1b64..00000000 Binary files a/GPy/testing/baseline/gplvm_latent_3d.png and /dev/null differ diff --git a/GPy/testing/baseline/gplvm_magnification.npz b/GPy/testing/baseline/gplvm_magnification.npz new file mode 100644 index 00000000..0a213c34 Binary files /dev/null and b/GPy/testing/baseline/gplvm_magnification.npz differ diff --git a/GPy/testing/baseline/gplvm_magnification.png b/GPy/testing/baseline/gplvm_magnification.png deleted file mode 100644 index a271cf6c..00000000 Binary files a/GPy/testing/baseline/gplvm_magnification.png and /dev/null differ diff --git a/GPy/testing/baseline/kern_ARD.npz b/GPy/testing/baseline/kern_ARD.npz new file mode 100644 index 00000000..996833b5 Binary files /dev/null and b/GPy/testing/baseline/kern_ARD.npz differ diff --git a/GPy/testing/baseline/kern_ARD.png b/GPy/testing/baseline/kern_ARD.png deleted file mode 100644 index e56a5312..00000000 Binary files a/GPy/testing/baseline/kern_ARD.png and /dev/null differ diff --git a/GPy/testing/baseline/kern_cov_1d.npz b/GPy/testing/baseline/kern_cov_1d.npz new file mode 100644 index 00000000..b66d7c9d Binary files /dev/null and b/GPy/testing/baseline/kern_cov_1d.npz differ diff --git a/GPy/testing/baseline/kern_cov_1d.png b/GPy/testing/baseline/kern_cov_1d.png deleted file mode 100644 index 64c3a57f..00000000 Binary files a/GPy/testing/baseline/kern_cov_1d.png and /dev/null differ diff --git a/GPy/testing/baseline/kern_cov_2d.npz b/GPy/testing/baseline/kern_cov_2d.npz new file mode 100644 index 00000000..b391339b Binary files /dev/null and b/GPy/testing/baseline/kern_cov_2d.npz differ diff --git a/GPy/testing/baseline/kern_cov_2d.png b/GPy/testing/baseline/kern_cov_2d.png deleted file mode 100644 index 1df0e5d0..00000000 Binary files a/GPy/testing/baseline/kern_cov_2d.png and /dev/null differ diff --git a/GPy/testing/baseline/kern_cov_3d.npz b/GPy/testing/baseline/kern_cov_3d.npz new file mode 100644 index 00000000..c424d35f Binary files /dev/null and b/GPy/testing/baseline/kern_cov_3d.npz differ diff --git a/GPy/testing/baseline/kern_cov_3d.png b/GPy/testing/baseline/kern_cov_3d.png deleted file mode 100644 index 52bff7cb..00000000 Binary files a/GPy/testing/baseline/kern_cov_3d.png and /dev/null differ diff --git a/GPy/testing/baseline/kern_cov_no_lim.npz b/GPy/testing/baseline/kern_cov_no_lim.npz new file mode 100644 index 00000000..52d8c633 Binary files /dev/null and b/GPy/testing/baseline/kern_cov_no_lim.npz differ diff --git a/GPy/testing/baseline/kern_cov_no_lim.png b/GPy/testing/baseline/kern_cov_no_lim.png deleted file mode 100644 index f8b91507..00000000 Binary files a/GPy/testing/baseline/kern_cov_no_lim.png and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_class_likelihood.npz b/GPy/testing/baseline/sparse_gp_class_likelihood.npz new file mode 100644 index 00000000..72a6cfc9 Binary files /dev/null and b/GPy/testing/baseline/sparse_gp_class_likelihood.npz differ diff --git a/GPy/testing/baseline/sparse_gp_class_likelihood.png b/GPy/testing/baseline/sparse_gp_class_likelihood.png deleted file mode 100644 index 55449be4..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_likelihood.png and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_class_raw.npz b/GPy/testing/baseline/sparse_gp_class_raw.npz new file mode 100644 index 00000000..b450f64b Binary files /dev/null and b/GPy/testing/baseline/sparse_gp_class_raw.npz differ diff --git a/GPy/testing/baseline/sparse_gp_class_raw.png b/GPy/testing/baseline/sparse_gp_class_raw.png deleted file mode 100644 index 484d15f9..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_raw.png 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 new file mode 100644 index 00000000..d0763e9a Binary files /dev/null and b/GPy/testing/baseline/sparse_gp_class_raw_link.npz differ diff --git a/GPy/testing/baseline/sparse_gp_class_raw_link.png b/GPy/testing/baseline/sparse_gp_class_raw_link.png deleted file mode 100644 index c5742464..00000000 Binary files a/GPy/testing/baseline/sparse_gp_class_raw_link.png and /dev/null differ diff --git a/GPy/testing/baseline/sparse_gp_data_error.npz b/GPy/testing/baseline/sparse_gp_data_error.npz new file mode 100644 index 00000000..0914952a Binary files /dev/null and b/GPy/testing/baseline/sparse_gp_data_error.npz differ diff --git a/GPy/testing/baseline/sparse_gp_data_error.png b/GPy/testing/baseline/sparse_gp_data_error.png deleted file mode 100644 index 9fe65c58..00000000 Binary files a/GPy/testing/baseline/sparse_gp_data_error.png and /dev/null differ diff --git a/GPy/testing/plotting_tests.py b/GPy/testing/plotting_tests.py index 3ab9ad10..f050943b 100644 --- a/GPy/testing/plotting_tests.py +++ b/GPy/testing/plotting_tests.py @@ -72,7 +72,7 @@ try: except ImportError: raise SkipTest("Matplotlib not installed, not testing plots") -extensions = ['png'] +extensions = ['npz'] def _image_directories(): """ @@ -93,39 +93,104 @@ baseline_dir, result_dir = _image_directories() if not os.path.exists(baseline_dir): raise SkipTest("Not installed from source, baseline not available. Install from source to test plotting") -def _sequenceEqual(a, b): - assert len(a) == len(b), "Sequences not same length" - for i, [x, y], in enumerate(zip(a, b)): - assert x == y, "element not matching {}".format(i) +def _image_comparison(baseline_images, extensions=['pdf','svg','png'], tol=11, decimal=6): -def _notFound(path): - raise IOError('File {} not in baseline') - -def _image_comparison(baseline_images, extensions=['pdf','svg','png'], tol=11): for num, base in zip(plt.get_fignums(), baseline_images): for ext in extensions: fig = plt.figure(num) + fig.canvas.draw() #fig.axes[0].set_axis_off() #fig.set_frameon(False) - fig.canvas.draw() - fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)), - transparent=True, - edgecolor='none', - facecolor='none', - #bbox='tight' - ) + 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' + ) + else: + fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)), + transparent=True, + edgecolor='none', + facecolor='none', + #bbox='tight' + ) for num, base in zip(plt.get_fignums(), baseline_images): for ext in extensions: #plt.close(num) actual = os.path.join(result_dir, "{}.{}".format(base, ext)) expected = os.path.join(baseline_dir, "{}.{}".format(base, ext)) - def do_test(): - err = compare_images(expected, actual, tol, in_decorator=True) - if err: - raise SkipTest("Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(actual, expected, err['rms'], tol)) + if ext == 'npz': + def do_test(): + if not os.path.exists(expected): + import shutil + shutil.copy2(actual, expected) + #shutil.copy2(os.path.join(result_dir, "{}.{}".format(base, 'png')), os.path.join(baseline_dir, "{}.{}".format(base, 'png'))) + raise IOError("Baseline file {} not found, copying result {}".format(expected, actual)) + else: + exp_dict = dict(np.load(expected).items()) + act_dict = dict(np.load(actual).items()) + assert(len(exp_dict)==len(act_dict)) + for name in exp_dict: + np.testing.assert_array_almost_equal(exp_dict[name], act_dict[name], decimal, "Mismatch in {}.{}".format(base, name)) + else: + def do_test(): + err = compare_images(expected, actual, tol, in_decorator=True) + if err: + raise SkipTest("Error between {} and {} is {:.5f}, which is bigger then the tolerance of {:.5f}".format(actual, expected, err['rms'], tol)) yield do_test plt.close('all') +def flatten_axis(ax, prevname=''): + import inspect + members = inspect.getmembers(ax) + + arrays = {} + + def _flatten(l, pre): + arr = {} + if isinstance(l, np.ndarray): + if l.size: + arr[pre] = np.asarray(l) + elif isinstance(l, dict): + for _n in l: + _tmp = _flatten(l, pre+"."+_n+".") + for _nt in _tmp.keys(): + arrays[_nt] = _tmp[_nt] + elif isinstance(l, list) and len(l)>0: + for i in range(len(l)): + _tmp = _flatten(l[i], pre+"[{}]".format(i)) + for _n in _tmp: + arr["{}".format(_n)] = _tmp[_n] + else: + return flatten_axis(l, pre+'.') + return arr + + + for name, l in members: + if isinstance(l, np.ndarray): + arrays[prevname+name] = np.asarray(l) + elif isinstance(l, list) and len(l)>0: + for i in range(len(l)): + _tmp = _flatten(l[i], prevname+name+"[{}]".format(i)) + for _n in _tmp: + arrays["{}".format(_n)] = _tmp[_n] + + return arrays + +def _a(x,y,decimal): + np.testing.assert_array_almost_equal(x, y, decimal) + +def compare_axis_dicts(x, y, decimal=6): + try: + assert(len(x)==len(y)) + for name in x: + _a(x[name], y[name], decimal) + except AssertionError as e: + raise SkipTest(e.message) + def test_figure(): np.random.seed(1239847) from GPy.plotting import plotting_library as pl