mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-05 01:32:40 +02:00
[coverage] covering all of gpy_plot
This commit is contained in:
parent
21690e2408
commit
81dc576ec4
9 changed files with 58 additions and 19 deletions
|
|
@ -97,22 +97,19 @@ class BufferedAxisChangedController(AxisChangedController):
|
|||
:param kwargs: additional kwargs are for pyplot.imshow(**kwargs)
|
||||
"""
|
||||
super(BufferedAxisChangedController, self).__init__(ax, update_lim=update_lim)
|
||||
self.resolution = resolution
|
||||
self.plot_function = plot_function
|
||||
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
|
||||
self.resolution = resolution
|
||||
self._not_init = False
|
||||
self.view = self._init_view(self.ax, self.recompute_X(buffered=False), xmin, xmax, ymin, ymax, **kwargs)
|
||||
self._not_init = True
|
||||
|
||||
def update(self, ax):
|
||||
super(BufferedAxisChangedController, self).update(ax)
|
||||
if self._not_init:
|
||||
xmin, xmax = self._compute_buffered(*self._x_lim)
|
||||
ymin, ymax = self._compute_buffered(*self._y_lim)
|
||||
self.update_view(self.view, self.recompute_X(), xmin, xmax, ymin, ymax)
|
||||
xmin, xmax = self._compute_buffered(*self._x_lim)
|
||||
ymin, ymax = self._compute_buffered(*self._y_lim)
|
||||
self.update_view(self.view, self.recompute_X(), xmin, xmax, ymin, ymax)
|
||||
|
||||
def _init_view(self, ax, X, xmin, xmax, ymin, ymax):
|
||||
raise NotImplementedError('return view for this controller')
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ 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):
|
||||
xoffset, yoffset = 0, 0#self._offsets(xmin, xmax, ymin, ymax)
|
||||
return canvas.imshow(X, extent=(xmin-xoffset, xmax+xoffset,
|
||||
ymin-yoffset, ymax+yoffset),
|
||||
#xoffset, yoffset = 0, 0#self._offsets(xmin, xmax, ymin, ymax)
|
||||
return canvas.imshow(X, extent=(xmin, xmax,
|
||||
ymin, ymax),
|
||||
vmin=vmin, vmax=vmax,
|
||||
**kwargs)
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class ImshowController(BufferedAxisChangedController):
|
|||
ymin-yoffset, ymax+yoffset))
|
||||
|
||||
def _offsets(self, xmin, xmax, ymin, ymax):
|
||||
return (xmax - xmin) / (2 * self.resolution), (ymax - ymin) / (2 * self.resolution)
|
||||
return float(xmax - xmin) / (2 * self.resolution), float(ymax - ymin) / (2 * self.resolution)
|
||||
|
||||
|
||||
class ImAnnotateController(ImshowController):
|
||||
|
|
|
|||
|
|
@ -65,10 +65,8 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
else:
|
||||
fig = self.figure()
|
||||
|
||||
if hasattr(fig, 'rows') and hasattr(fig, 'cols'):
|
||||
ax = fig.add_subplot(fig.rows, fig.cols, (col,row), projection=projection)
|
||||
else:
|
||||
ax = fig.add_subplot(1, 1, (1, 1), projection=projection)
|
||||
#if hasattr(fig, 'rows') and hasattr(fig, 'cols'):
|
||||
ax = fig.add_subplot(fig.rows, fig.cols, (col,row), projection=projection)
|
||||
|
||||
if xlim is not None: ax.set_xlim(xlim)
|
||||
if ylim is not None: ax.set_ylim(ylim)
|
||||
|
|
@ -149,13 +147,14 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
#xmin, xmax, ymin, ymax = extent = xmin-xoffset, xmax+xoffset, ymin-yoffset, ymax+yoffset
|
||||
return ax.imshow(X, label=label, extent=extent, vmin=vmin, vmax=vmax, **imshow_kwargs)
|
||||
|
||||
def imshow_interact(self, ax, plot_function, extent=None, label=None, resolution=None, vmin=None, vmax=None, **imshow_kwargs):
|
||||
def imshow_interact(self, ax, plot_function, extent, label=None, resolution=None, vmin=None, vmax=None, **imshow_kwargs):
|
||||
if imshow_kwargs is None: imshow_kwargs = {}
|
||||
if 'origin' not in imshow_kwargs:
|
||||
imshow_kwargs['origin'] = 'lower'
|
||||
return ImshowController(ax, plot_function, extent, resolution=resolution, vmin=vmin, vmax=vmax, **imshow_kwargs)
|
||||
|
||||
def annotation_heatmap(self, ax, X, annotation, extent=None, label=None, imshow_kwargs=None, **annotation_kwargs):
|
||||
imshow_kwargs = imshow_kwargs or {}
|
||||
if imshow_kwargs is None: imshow_kwargs = {}
|
||||
if 'origin' not in imshow_kwargs:
|
||||
imshow_kwargs['origin'] = 'lower'
|
||||
if ('ha' not in annotation_kwargs) and ('horizontalalignment' not in annotation_kwargs):
|
||||
|
|
@ -175,6 +174,7 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
return imshow, annotations
|
||||
|
||||
def annotation_heatmap_interact(self, ax, plot_function, extent, label=None, resolution=15, imshow_kwargs=None, **annotation_kwargs):
|
||||
if imshow_kwargs is None: imshow_kwargs = {}
|
||||
if 'origin' not in imshow_kwargs:
|
||||
imshow_kwargs['origin'] = 'lower'
|
||||
return ImAnnotateController(ax, plot_function, extent, resolution=resolution, imshow_kwargs=imshow_kwargs or {}, **annotation_kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue