[docs] updated and testing
|
|
@ -1,6 +1,11 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
"""
|
||||
Examples for GPy.
|
||||
|
||||
The examples in this package usually depend on `pods <https://github.com/sods/ods>`_ so make sure
|
||||
you have that installed before running examples.
|
||||
"""
|
||||
from . import classification
|
||||
from . import regression
|
||||
from . import dimensionality_reduction
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
# Copyright (c) 2012-2014, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
|
||||
"""
|
||||
Gaussian Processes classification examples
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
"""
|
||||
Kernel module the kernels to sit in.
|
||||
|
||||
.. automodule:: GPy.kern.src
|
||||
:members:
|
||||
:private-members:
|
||||
"""
|
||||
from . import _src as src
|
||||
from ._src.kern import Kern
|
||||
from ._src.rbf import RBF
|
||||
from ._src.linear import Linear, LinearFull
|
||||
|
|
@ -20,5 +28,4 @@ from ._src.splitKern import SplitKern,DEtime
|
|||
from ._src.splitKern import DEtime as DiffGenomeKern
|
||||
from ._src.spline import Spline
|
||||
from ._src.eq_ode2 import EQ_ODE2
|
||||
from ._src.basis_funcs import LinearSlopeBasisFuncKernel, BasisFuncKernel, ChangePointBasisFuncKernel, DomainKernel
|
||||
|
||||
from ._src.basis_funcs import LinearSlopeBasisFuncKernel, BasisFuncKernel, ChangePointBasisFuncKernel, DomainKernel
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
# Copyright (c) 2012, GPy authors (see AUTHORS.txt).
|
||||
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||
|
||||
import sys
|
||||
import numpy as np
|
||||
from ...core.parameterization.parameterized import Parameterized
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ if config.get('plotting', 'library') is not 'none':
|
|||
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
||||
|
||||
from ..kern import Kern
|
||||
#Kern.plot_covariance = gpy_plot.kern_plots.plot_kern
|
||||
Kern.plot_covariance = gpy_plot.kernel_plots.plot_covariance
|
||||
Kern.plot_covariance = gpy_plot.kernel_plots.plot_ARD
|
||||
|
||||
# Variational plot!
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class AbstractPlottingLibrary(object):
|
|||
return self.__defaults
|
||||
#===============================================================================
|
||||
|
||||
def get_new_canvas(self, xlabel=None, ylabel=None, zlabel=None, title=None, projection='2d', legend=True, **kwargs):
|
||||
def get_new_canvas(self, projection='2d', legend=True, **kwargs):
|
||||
"""
|
||||
Return a canvas, kwargupdate for your plotting library.
|
||||
|
||||
|
|
@ -67,19 +67,14 @@ class AbstractPlottingLibrary(object):
|
|||
|
||||
the kwargs are plotting library specific kwargs!
|
||||
|
||||
:param bool plot_3d: whether to plot in 3d.
|
||||
:param xlabel: the label to put on the xaxis
|
||||
:param ylabel: the label to put on the yaxis
|
||||
:param zlabel: the label to put on the zaxis (if plotting in 3d)
|
||||
:param title: the title of the plot
|
||||
:param legend: whether to put a legend on
|
||||
:param {'2d'|'3d'} projection: The projection to use.
|
||||
|
||||
E.g. in matplotlib this means it deletes references to ax, as
|
||||
plotting is done on the axis itself and is not a kwarg.
|
||||
"""
|
||||
raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library")
|
||||
|
||||
def show_canvas(self, canvas, plots, 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, **kwargs):
|
||||
"""
|
||||
Show the canvas given.
|
||||
plots is a dictionary with the plots
|
||||
|
|
@ -87,6 +82,11 @@ class AbstractPlottingLibrary(object):
|
|||
|
||||
the kwargs are plotting library specific kwargs!
|
||||
|
||||
:param xlabel: the label to put on the xaxis
|
||||
:param ylabel: the label to put on the yaxis
|
||||
:param zlabel: the label to put on the zaxis (if plotting in 3d)
|
||||
:param title: the title of the plot
|
||||
:param legend: if True, plot a legend, if int make legend rows in the legend
|
||||
:param (float, float) xlim: the limits for the xaxis
|
||||
:param (float, float) ylim: the limits for the yaxis
|
||||
:param (float, float) zlim: the limits for the zaxis (if plotting in 3d)
|
||||
|
|
@ -185,6 +185,8 @@ class AbstractPlottingLibrary(object):
|
|||
Just ignore the plot_function, if you do not have the option
|
||||
to have interactive changes.
|
||||
|
||||
The origin of the image show is (0,0), such that X[0,0] gets plotted at [0,0] of the image!
|
||||
|
||||
the kwargs are plotting library specific kwargs!
|
||||
"""
|
||||
raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library")
|
||||
|
|
@ -211,6 +213,7 @@ class AbstractPlottingLibrary(object):
|
|||
:param str label: the label for the heatmap
|
||||
:param plot_function: the function, which generates new data for given input locations X
|
||||
:param int resolution: the resolution of the interactive plot redraw - this is only needed when giving a plot_function
|
||||
:return: a list of both the heatmap and annotation plots [heatmap, annotation]
|
||||
"""
|
||||
raise NotImplementedError("Implement all plot functions in AbstractPlottingLibrary in order to use your own plotting library")
|
||||
|
||||
|
|
|
|||
|
|
@ -68,15 +68,7 @@ def plot_ARD(kernel, filtering=None, **kwargs):
|
|||
ax.set_xlim(-.5, kernel.input_dim - .5)
|
||||
add_bar_labels(fig, ax, [bars[-1]], bottom=bottom-last_bottom)
|
||||
|
||||
if legend:
|
||||
if title is '':
|
||||
mode = 'expand'
|
||||
if len(bars) > 1:
|
||||
mode = 'expand'
|
||||
ax.legend(bbox_to_anchor=(0., 1.02, 1., 1.02), loc=3,
|
||||
ncol=len(bars), mode=mode, borderaxespad=0.)
|
||||
fig.tight_layout(rect=(0, 0, 1, .9))
|
||||
else:
|
||||
ax.legend()
|
||||
return dict(barplots=bars)
|
||||
|
||||
return dict(barplots=bars)
|
||||
def plot_covariance():
|
||||
pass
|
||||
|
|
@ -29,19 +29,23 @@
|
|||
#===============================================================================
|
||||
import numpy as np
|
||||
from . import pl
|
||||
from .plot_util import get_x_y_var, get_free_dims, get_which_data_ycols,\
|
||||
from .plot_util import get_x_y_var, get_which_data_ycols,\
|
||||
get_which_data_rows, update_not_existing_kwargs, helper_predict_with_model,\
|
||||
helper_for_plot_data
|
||||
import itertools
|
||||
from GPy.plotting.gpy_plot.plot_util import scatter_label_generator, subsample_X
|
||||
helper_for_plot_data, scatter_label_generator, subsample_X,\
|
||||
find_best_layout_for_subplots
|
||||
|
||||
def _wait_for_updates(view, updates):
|
||||
if updates:
|
||||
clear = raw_input('yes or enter to deactivate updates - otherwise still do updates - use plots[imshow].deactivate() to clear')
|
||||
if clear.lower() in 'yes' or clear == '':
|
||||
try:
|
||||
if updates:
|
||||
clear = raw_input('yes or enter to deactivate updates - otherwise still do updates - use plots[imshow].deactivate() to clear')
|
||||
if clear.lower() in 'yes' or clear == '':
|
||||
view.deactivate()
|
||||
else:
|
||||
view.deactivate()
|
||||
else:
|
||||
view.deactivate()
|
||||
except AttributeError:
|
||||
# No updateable view:
|
||||
pass
|
||||
|
||||
|
||||
def plot_prediction_fit(self, plot_limits=None,
|
||||
which_data_rows='all', which_data_ycols='all',
|
||||
|
|
@ -160,12 +164,11 @@ def _plot_magnification(self, canvas, input_1, input_2, Xgrid,
|
|||
Xtest_full = np.zeros((x.shape[0], Xgrid.shape[1]))
|
||||
Xtest_full[:, [input_1, input_2]] = x
|
||||
mf = self.predict_magnification(Xtest_full, kern=kern, mean=mean, covariance=covariance)
|
||||
return mf.reshape(resolution, resolution).T[::-1, :]
|
||||
|
||||
return mf.reshape(resolution, resolution).T
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.magnification)
|
||||
Y = plot_function(Xgrid[:, [input_1, input_2]])
|
||||
view = pl.imshow(canvas, Y,
|
||||
(xmin[0], xmin[1], xmax[1], xmax[1]),
|
||||
(xmin[0], xmax[0], xmin[1], xmax[1]),
|
||||
None, plot_function, resolution,
|
||||
vmin=Y.min(), vmax=Y.max(),
|
||||
**imshow_kwargs)
|
||||
|
|
@ -177,8 +180,7 @@ def plot_magnification(self, labels=None, which_indices=None,
|
|||
updates=False,
|
||||
mean=True, covariance=True,
|
||||
kern=None, num_samples=1000,
|
||||
imshow_kwargs=None,
|
||||
**scatter_kwargs):
|
||||
scatter_kwargs=None, **imshow_kwargs):
|
||||
"""
|
||||
Plot the magnification factor of the GP on the inputs. This is the
|
||||
density of the GP as a gray scale.
|
||||
|
|
@ -199,12 +201,16 @@ def plot_magnification(self, labels=None, which_indices=None,
|
|||
:param kwargs: the kwargs for the scatter plots
|
||||
"""
|
||||
input_1, input_2 = self.get_most_significant_input_dimensions(which_indices)
|
||||
canvas, scatter_kwargs = pl.get_new_canvas(xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **scatter_kwargs)
|
||||
canvas, imshow_kwargs = pl.get_new_canvas(**imshow_kwargs)
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, (input_1, input_2), None, resolution)
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **scatter_kwargs)
|
||||
if imshow_kwargs is None: imshow_kwargs = {}
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **scatter_kwargs or {})
|
||||
view = _plot_magnification(self, canvas, input_1, input_2, Xgrid, xmin, xmax, resolution, mean, covariance, kern, **imshow_kwargs)
|
||||
plots = pl.show_canvas(canvas, dict(scatter=scatters, imshow=view), legend=legend and (labels is not None), xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]))
|
||||
if (legend is True) and (labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
|
||||
plots = pl.show_canvas(canvas, dict(scatter=scatters, imshow=view),
|
||||
legend=legend,
|
||||
xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2)
|
||||
_wait_for_updates(view, updates)
|
||||
return plots
|
||||
|
||||
|
|
@ -219,12 +225,12 @@ def _plot_latent(self, canvas, input_1, input_2, Xgrid,
|
|||
Xtest_full = np.zeros((x.shape[0], Xgrid.shape[1]))
|
||||
Xtest_full[:, [input_1, input_2]] = x
|
||||
mf = np.log(self.predict(Xtest_full, kern=kern)[1])
|
||||
return mf.reshape(resolution, resolution).T[::-1, :]
|
||||
return mf.reshape(resolution, resolution).T
|
||||
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.latent)
|
||||
Y = plot_function(Xgrid[:, [input_1, input_2]]).reshape(resolution, resolution).T[::-1, :]
|
||||
Y = plot_function(Xgrid[:, [input_1, input_2]]).reshape(resolution, resolution).T
|
||||
view = pl.imshow(canvas, Y,
|
||||
(xmin[0], xmin[1], xmax[1], xmax[1]),
|
||||
(xmin[0], xmax[0], xmin[1], xmax[1]),
|
||||
None, plot_function, resolution,
|
||||
vmin=Y.min(), vmax=Y.max(),
|
||||
**imshow_kwargs)
|
||||
|
|
@ -236,7 +242,7 @@ def plot_latent(self, labels=None, which_indices=None,
|
|||
updates=False,
|
||||
kern=None, marker='<>^vsd',
|
||||
num_samples=1000,
|
||||
imshow_kwargs=None, **scatter_kwargs):
|
||||
scatter_kwargs=None, **imshow_kwargs):
|
||||
"""
|
||||
Plot the latent space of the GP on the inputs. This is the
|
||||
density of the GP posterior as a grey scale and the
|
||||
|
|
@ -256,12 +262,16 @@ def plot_latent(self, labels=None, which_indices=None,
|
|||
:param scatter_kwargs: the kwargs for the scatter plots
|
||||
"""
|
||||
input_1, input_2 = self.get_most_significant_input_dimensions(which_indices)
|
||||
canvas, scatter_kwargs = pl.get_new_canvas(xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **scatter_kwargs)
|
||||
canvas, imshow_kwargs = pl.get_new_canvas(**imshow_kwargs)
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, (input_1, input_2), None, resolution)
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **scatter_kwargs)
|
||||
if imshow_kwargs is None: imshow_kwargs = {}
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, labels, marker, num_samples, **scatter_kwargs or {})
|
||||
view = _plot_latent(self, canvas, input_1, input_2, Xgrid, xmin, xmax, resolution, kern, **imshow_kwargs)
|
||||
plots = pl.show_canvas(canvas, dict(scatter=scatters, imshow=view), legend=legend and (labels is not None), xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]))
|
||||
if (legend is True) and (labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
|
||||
plots = pl.show_canvas(canvas, dict(scatter=scatters, imshow=view),
|
||||
legend=legend,
|
||||
xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2)
|
||||
_wait_for_updates(view, updates)
|
||||
return plots
|
||||
|
||||
|
|
@ -275,14 +285,14 @@ def _plot_steepest_gradient_map(self, canvas, input_1, input_2, Xgrid,
|
|||
Xgrid[:, [input_1, input_2]] = x
|
||||
dmu_dX = self.predictive_gradients(Xgrid, kern=kern)[0].sum(1)
|
||||
argmax = np.argmax(dmu_dX, 1).astype(int)
|
||||
return dmu_dX.max(1).reshape(resolution, resolution).T[::-1, :], np.array(output_labels)[argmax].reshape(resolution, resolution)
|
||||
return dmu_dX.max(1).reshape(resolution, resolution).T, np.array(output_labels)[argmax].reshape(resolution, resolution)
|
||||
Y, annotation = plot_function(Xgrid[:, [input_1, input_2]])
|
||||
annotation_kwargs = update_not_existing_kwargs(annotation_kwargs or {}, pl.defaults.annotation)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs or {}, pl.defaults.gradient)
|
||||
annotation = pl.annotation_heatmap(canvas, Y, annotation, (xmin[0], xmin[1], xmax[1], xmax[1]),
|
||||
imshow, annotation = pl.annotation_heatmap(canvas, Y, annotation, (xmin[0], xmax[0], xmin[1], xmax[1]),
|
||||
None, plot_function, resolution, imshow_kwargs=imshow_kwargs, **annotation_kwargs)
|
||||
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.gradient)
|
||||
return dict(annotation=annotation)
|
||||
return dict(heatmap=imshow, annotation=annotation)
|
||||
|
||||
def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which_indices=None,
|
||||
resolution=15, legend=True,
|
||||
|
|
@ -300,7 +310,7 @@ def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which
|
|||
:param array-like labels: a label for each data point (row) of the inputs
|
||||
:param (int, int) which_indices: which input dimensions to plot against each other
|
||||
:param int resolution: the resolution at which we predict the magnification factor
|
||||
:param bool legend: whether to plot the legend on the figure
|
||||
:param bool legend: whether to plot the legend on the figure, if int plot legend columns on legend
|
||||
:param plot_limits: the plot limits for the plot
|
||||
:type plot_limits: (xmin, xmax, ymin, ymax) or ((xmin, xmax), (ymin, ymax))
|
||||
:param bool updates: if possible, make interactive updates using the specific library you are using
|
||||
|
|
@ -312,12 +322,16 @@ def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which
|
|||
:param scatter_kwargs: the kwargs for the scatter plots
|
||||
"""
|
||||
input_1, input_2 = self.get_most_significant_input_dimensions(which_indices)
|
||||
canvas, imshow_kwargs = pl.get_new_canvas(xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2, **imshow_kwargs)
|
||||
canvas, imshow_kwargs = pl.get_new_canvas(**imshow_kwargs)
|
||||
X, _, _, _, _, Xgrid, _, _, xmin, xmax, resolution = helper_for_plot_data(self, plot_limits, (input_1, input_2), None, resolution)
|
||||
scatters = _plot_latent_scatter(self, canvas, X, input_1, input_2, data_labels, marker, num_samples, **scatter_kwargs or {})
|
||||
view = _plot_steepest_gradient_map(self, canvas, input_1, input_2, Xgrid, xmin, xmax, resolution, output_labels, kern, annotation_kwargs=annotation_kwargs, **imshow_kwargs)
|
||||
plots = pl.show_canvas(canvas, dict(scatter=scatters, imshow=view), legend=legend and (data_labels is not None), xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]))
|
||||
_wait_for_updates(view['annotation'], updates)
|
||||
plots = dict(scatter=_plot_latent_scatter(self, canvas, X, input_1, input_2, data_labels, marker, num_samples, **scatter_kwargs or {}))
|
||||
plots.update(_plot_steepest_gradient_map(self, canvas, input_1, input_2, Xgrid, xmin, xmax, resolution, output_labels, kern, annotation_kwargs=annotation_kwargs, **imshow_kwargs))
|
||||
if (legend is True) and (data_labels is not None):
|
||||
legend = find_best_layout_for_subplots(len(np.unique(data_labels)))[1]
|
||||
pl.show_canvas(canvas, plots, legend=legend,
|
||||
xlim=(xmin[0], xmax[0]), ylim=(xmin[1], xmax[1]),
|
||||
xlabel='latent dimension %i' % input_1, ylabel='latent dimension %i' % input_2)
|
||||
_wait_for_updates(plots['annotation'], updates)
|
||||
return plots
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,17 @@ import numpy as np
|
|||
from scipy import sparse
|
||||
import itertools
|
||||
|
||||
|
||||
def find_best_layout_for_subplots(num_subplots):
|
||||
r, c = 1, 1
|
||||
while (r*c) < num_subplots:
|
||||
if (c==(r+1)) or (r==c):
|
||||
c += 1
|
||||
elif c==(r+2):
|
||||
r += 1
|
||||
c -= 1
|
||||
return r, c
|
||||
|
||||
def helper_predict_with_model(self, Xgrid, plot_raw, apply_link, percentiles, which_data_ycols, predict_kw, samples=0):
|
||||
"""
|
||||
Make the right decisions for prediction with a model
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class AxisEventController(object):
|
|||
return self
|
||||
def deactivate(self):
|
||||
for cb_class in self.ax.callbacks.callbacks.values():
|
||||
for cb_num in cb_class.keys():
|
||||
for cb_num in cb_class.keys()[:]:
|
||||
self.ax.callbacks.disconnect(cb_num)
|
||||
def activate(self):
|
||||
self.ax.callbacks.connect('xlim_changed', self.xlim_changed)
|
||||
|
|
@ -98,7 +98,7 @@ class BufferedAxisChangedController(AxisChangedController):
|
|||
"""
|
||||
super(BufferedAxisChangedController, self).__init__(ax, update_lim=update_lim)
|
||||
self.plot_function = plot_function
|
||||
xmin, ymin, xmax, ymax = plot_limits#self._x_lim # self._compute_buffered(*self._x_lim)
|
||||
xmin, xmax, ymin, ymax = plot_limits#self._x_lim # self._compute_buffered(*self._x_lim)
|
||||
# imshow acts on the limits of the plot, this is why we need to override the limits here, to make sure the right plot limits are used:
|
||||
self._x_lim = xmin, xmax
|
||||
self._y_lim = ymin, ymax
|
||||
|
|
|
|||
|
|
@ -23,14 +23,21 @@ class ImshowController(BufferedAxisChangedController):
|
|||
super(ImshowController, self).__init__(ax, plot_function, plot_limits, resolution, update_lim, **kwargs)
|
||||
|
||||
def _init_view(self, canvas, X, xmin, xmax, ymin, ymax, vmin=None, vmax=None, **kwargs):
|
||||
return canvas.imshow(X, extent=(xmin, xmax,
|
||||
ymin, ymax),
|
||||
xoffset, yoffset = self._offsets(xmin, xmax, ymin, ymax)
|
||||
return canvas.imshow(X, extent=(xmin-xoffset, xmax+xoffset,
|
||||
ymin-yoffset, ymax+yoffset),
|
||||
vmin=vmin, vmax=vmax,
|
||||
**kwargs)
|
||||
**kwargs)
|
||||
|
||||
def update_view(self, view, X, xmin, xmax, ymin, ymax):
|
||||
view.set_data(X)
|
||||
view.set_extent((xmin, xmax, ymin, ymax))
|
||||
xoffset, yoffset = self._offsets(xmin, xmax, ymin, ymax)
|
||||
view.set_extent((xmin-xoffset, xmax+xoffset,
|
||||
ymin-yoffset, ymax+yoffset))
|
||||
|
||||
def _offsets(self, xmin, xmax, ymin, ymax):
|
||||
return (xmax - xmin) / (2 * self.resolution), (ymax - ymin) / (2 * self.resolution)
|
||||
|
||||
|
||||
class ImAnnotateController(ImshowController):
|
||||
def __init__(self, ax, plot_function, plot_limits, resolution=20, update_lim=.99, imshow_kwargs=None, **kwargs):
|
||||
|
|
@ -65,7 +72,4 @@ class ImAnnotateController(ImshowController):
|
|||
text.set_x(x + xoffset)
|
||||
text.set_y(y + yoffset)
|
||||
text.set_text("{}".format(X[1][j, i]))
|
||||
return view
|
||||
|
||||
def _offsets(self, xmin, xmax, ymin, ymax):
|
||||
return (xmax - xmin) / (2 * self.resolution), (ymax - ymin) / (2 * self.resolution)
|
||||
return view
|
||||
|
|
@ -69,7 +69,7 @@ ard = dict(edgecolor='k', linewidth=1.2)
|
|||
|
||||
# Input plots:
|
||||
latent = dict(aspect='auto', cmap='Greys', interpolation='bicubic')
|
||||
gradient = dict(aspect='auto', cmap='RdBu', interpolation='nearest')
|
||||
gradient = dict(aspect='auto', cmap='RdBu', interpolation='nearest', alpha=.7)
|
||||
magnification = dict(aspect='auto', cmap='Greys', interpolation='bicubic')
|
||||
latent_scatter = dict(s=40, linewidth=.2, edgecolor='k', alpha=.9)
|
||||
annotation = dict(fontdict=dict(family='sans-serif', weight='light', fontsize=9), zorder=.3)
|
||||
annotation = dict(fontdict=dict(family='sans-serif', weight='light', fontsize=9), zorder=.3, alpha=.7)
|
||||
|
|
@ -35,13 +35,14 @@ from . import defaults
|
|||
from matplotlib.colors import LinearSegmentedColormap
|
||||
from .controllers import ImshowController, ImAnnotateController
|
||||
import itertools
|
||||
from GPy.plotting.matplot_dep.util import legend_ontop
|
||||
|
||||
class MatplotlibPlots(AbstractPlottingLibrary):
|
||||
def __init__(self):
|
||||
super(MatplotlibPlots, self).__init__()
|
||||
self._defaults = defaults.__dict__
|
||||
|
||||
def get_new_canvas(self, xlabel=None, ylabel=None, zlabel=None, title=None, projection='2d', **kwargs):
|
||||
def get_new_canvas(self, projection='2d', **kwargs):
|
||||
if projection == '3d':
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
elif projection == '2d':
|
||||
|
|
@ -57,24 +58,23 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
else:
|
||||
ax = plt.figure().add_subplot(111, projection=projection)
|
||||
|
||||
return ax, kwargs
|
||||
|
||||
def show_canvas(self, ax, plots, xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, legend=False, **kwargs):
|
||||
ax.autoscale_view()
|
||||
ax.set_xlim(xlim)
|
||||
ax.set_ylim(ylim)
|
||||
if xlabel is not None: ax.set_xlabel(xlabel)
|
||||
if ylabel is not None: ax.set_ylabel(ylabel)
|
||||
if zlabel is not None: ax.set_zlabel(zlabel)
|
||||
if title is not None: ax.set_title(title)
|
||||
return ax, kwargs
|
||||
|
||||
def show_canvas(self, ax, plots, xlim=None, ylim=None, zlim=None, legend=False, **kwargs):
|
||||
try:
|
||||
ax.autoscale_view()
|
||||
ax.set_xlim(xlim)
|
||||
ax.set_ylim(ylim)
|
||||
if legend:
|
||||
ax.legend()
|
||||
if zlim is not None:
|
||||
ax.set_zlim(zlim)
|
||||
ax.figure.canvas.draw()
|
||||
except:
|
||||
pass
|
||||
fontdict=dict(family='sans-serif', weight='light', size=9)
|
||||
if legend >= 1:
|
||||
#ax.legend(prop=fontdict)
|
||||
legend_ontop(ax, ncol=legend)
|
||||
if zlim is not None:
|
||||
ax.set_zlim(zlim)
|
||||
ax.figure.canvas.draw()
|
||||
return plots
|
||||
|
||||
def scatter(self, ax, X, Y, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, marker='o', **kwargs):
|
||||
|
|
@ -119,27 +119,32 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
return ax.errorbar(X, Y, Z, yerr=error, ecolor=color, label=label, **kwargs)
|
||||
return ax.errorbar(X, Y, yerr=error, ecolor=color, label=label, **kwargs)
|
||||
|
||||
def imshow(self, ax, X, extent=None, label=None, plot_function=None, resolution=None, vmin=None, vmax=None, **kwargs):
|
||||
def imshow(self, ax, X, extent=None, label=None, plot_function=None, resolution=None, vmin=None, vmax=None, **imshow_kwargs):
|
||||
if 'origin' not in imshow_kwargs:
|
||||
imshow_kwargs['origin'] = 'lower'
|
||||
if plot_function is not None:
|
||||
return ImshowController(ax, plot_function, extent, resolution=resolution, vmin=vmin, vmax=vmax, **kwargs)
|
||||
return ax.imshow(X, label=label, extent=extent, vmin=vmin, vmax=vmax, **kwargs)
|
||||
return ImshowController(ax, plot_function, extent, resolution=resolution, vmin=vmin, vmax=vmax, **imshow_kwargs)
|
||||
return ax.imshow(X, label=label, extent=extent, vmin=vmin, vmax=vmax, **imshow_kwargs)
|
||||
|
||||
def annotation_heatmap(self, ax, X, annotation, extent, label=None, plot_function=None, resolution=None, imshow_kwargs=None, **annotation_kwargs):
|
||||
imshow_kwargs = imshow_kwargs or {}
|
||||
if 'origin' not in imshow_kwargs:
|
||||
imshow_kwargs['origin'] = 'lower'
|
||||
if plot_function is not None:
|
||||
return ImAnnotateController(ax, plot_function, extent, resolution=resolution, imshow_kwargs=imshow_kwargs or {}, **annotation_kwargs)
|
||||
if ('ha' not in annotation_kwargs) and ('horizontalalignment' not in annotation_kwargs):
|
||||
annotation_kwargs['ha'] = 'center'
|
||||
if ('va' not in annotation_kwargs) and ('verticalalignment' not in annotation_kwargs):
|
||||
annotation_kwargs['va'] = 'center'
|
||||
imshow = self.imshow(ax, X, extent, label, None, resolution, **imshow_kwargs)
|
||||
xmin, xmax, ymin, ymax = extent
|
||||
self.imshow(X, extent, label, None, resolution, **imshow_kwargs or {})
|
||||
xoffset, yoffset = (xmax - xmin) / (2 * self.resolution), (ymax - ymin) / (2 * self.resolution)
|
||||
xlin = np.linspace(xmin, xmax, self.resolution, endpoint=False)
|
||||
ylin = np.linspace(ymin, ymax, self.resolution, endpoint=False)
|
||||
xoffset, yoffset = (xmax - xmin) / (2. * resolution), (ymax - ymin) / (2. * resolution)
|
||||
xlin = np.linspace(xmin, xmax, resolution, endpoint=False)
|
||||
ylin = np.linspace(ymin, ymax, resolution, endpoint=False)
|
||||
annotations = []
|
||||
for [i, x], [j, y] in itertools.product(enumerate(xlin), enumerate(ylin[::-1])):
|
||||
annotations.append(ax.text(x + xoffset, y + yoffset, "{}".format(annotation[j, i]), **annotation_kwargs))
|
||||
return annotations
|
||||
return [imshow, annotations]
|
||||
|
||||
def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs):
|
||||
return ax.contour(X, Y, C, levels=np.linspace(C.min(), C.max(), levels), label=label, **kwargs)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,18 @@
|
|||
from matplotlib import pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def legend_ontop(ax, mode='expand', ncol=3, fontdict=None):
|
||||
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
||||
handles, labels = ax.get_legend_handles_labels()
|
||||
divider = make_axes_locatable(ax)
|
||||
cax = divider.append_axes("top", "5%", pad="1%")
|
||||
lgd = cax.legend(handles, labels, bbox_to_anchor=(0., 0., 1., 1.), loc=3,
|
||||
ncol=ncol, mode=mode, borderaxespad=0., prop=fontdict or {})
|
||||
cax.set_axis_off()
|
||||
#lgd = cax.legend(bbox_to_anchor=(0., 1.02, 1., 1.02), loc=3,
|
||||
# ncol=ncol, mode=mode, borderaxespad=0., prop=fontdict or {})
|
||||
return lgd
|
||||
|
||||
def removeRightTicks(ax=None):
|
||||
ax = ax or plt.gca()
|
||||
for i, line in enumerate(ax.get_yticklines()):
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |