[plotly] everything working, except gradient

This commit is contained in:
mzwiessele 2015-10-09 08:10:25 +01:00
parent b3154e43b4
commit 3bc0918a2b
4 changed files with 31 additions and 18 deletions

View file

@ -1,5 +1,5 @@
# This is the local installation configuration file for GPy # This is the local installation configuration file for GPy
[plotting] [plotting]
library = plotly #library = plotly
#library = matplotlib library = matplotlib

View file

@ -341,7 +341,7 @@ def x_frame1D(X,plot_limits=None,resolution=None):
xmin,xmax = X.mean.min(0),X.mean.max(0) xmin,xmax = X.mean.min(0),X.mean.max(0)
else: else:
xmin,xmax = X.min(0),X.max(0) xmin,xmax = X.min(0),X.max(0)
xmin, xmax = xmin-0.2*(xmax-xmin), xmax+0.2*(xmax-xmin) xmin, xmax = xmin-0.25*(xmax-xmin), xmax+0.25*(xmax-xmin)
elif len(plot_limits)==2: elif len(plot_limits)==2:
xmin, xmax = plot_limits xmin, xmax = plot_limits
else: else:
@ -357,7 +357,7 @@ def x_frame2D(X,plot_limits=None,resolution=None):
assert X.shape[1]==2, "x_frame2D is defined for two-dimensional inputs" assert X.shape[1]==2, "x_frame2D is defined for two-dimensional inputs"
if plot_limits is None: if plot_limits is None:
xmin, xmax = X.min(0),X.max(0) xmin, xmax = X.min(0),X.max(0)
xmin, xmax = xmin-0.2*(xmax-xmin), xmax+0.2*(xmax-xmin) xmin, xmax = xmin-0.075*(xmax-xmin), xmax+0.075*(xmax-xmin)
elif len(plot_limits)==2: elif len(plot_limits)==2:
xmin, xmax = plot_limits xmin, xmax = plot_limits
elif len(plot_limits)==4: elif len(plot_limits)==4:

View file

@ -48,7 +48,7 @@ data_2d = dict(marker='o', cmap='Hot', marker_kwargs=dict(opacity=1., size='10',
inducing_1d = dict(color=Tango.colorsHex['darkRed']) inducing_1d = dict(color=Tango.colorsHex['darkRed'])
inducing_2d = dict(marker_kwargs=dict(size='8', opacity=.7, line=Line(width=.5, color='black')), opacity=.7, color='white', marker='star-triangle-up') inducing_2d = dict(marker_kwargs=dict(size='8', opacity=.7, line=Line(width=.5, color='black')), opacity=.7, color='white', marker='star-triangle-up')
inducing_3d = dict(marker_kwargs=dict(size='8', opacity=.7, line=Line(width=.5, color='black')), opacity=.7, color='white', marker='star-triangle-up') inducing_3d = dict(marker_kwargs=dict(size='8', opacity=.7, line=Line(width=.5, color='black')), opacity=.7, color='white', marker='star-triangle-up')
# xerrorbar = dict(color='k', fmt='none', elinewidth=.5, alpha=.5) xerrorbar = dict(color='black', error_kwargs=dict(thickness=.5), opacity=.5)
yerrorbar = dict(color=Tango.colorsHex['darkRed'], error_kwargs=dict(thickness=.5), opacity=.5) yerrorbar = dict(color=Tango.colorsHex['darkRed'], error_kwargs=dict(thickness=.5), opacity=.5)
# #
# # GP plots: # # GP plots:
@ -69,8 +69,8 @@ confidence_interval = dict(mode='lines', line_kwargs=dict(color=Tango.colorsHex[
# ard = dict(edgecolor='k', linewidth=1.2) # ard = dict(edgecolor='k', linewidth=1.2)
# #
# # Input plots: # # Input plots:
latent = dict(colorscale='Greys', reversescale=True) latent = dict(colorscale='Greys', reversescale=True, zsmooth='best')
gradient = dict(colorscale='RdBu', opacity=.7) gradient = dict(colorscale='RdBu', opacity=.7)
magnification = dict(colorscale='Greys') magnification = dict(colorscale='Greys', zsmooth='best', reversescale=True)
latent_scatter = dict(marker_kwargs=dict(size='15', opacity=.7)) latent_scatter = dict(marker_kwargs=dict(size='15', opacity=.7))
# annotation = dict(fontdict=dict(family='sans-serif', weight='light', fontsize=9), zorder=.3, alpha=.7) # annotation = dict(fontdict=dict(family='sans-serif', weight='light', fontsize=9), zorder=.3, alpha=.7)

View file

@ -171,9 +171,16 @@ class PlotlyPlots(AbstractPlottingLibrary):
else: else:
error_kwargs.update(dict(array=error, symmetric=True)) error_kwargs.update(dict(array=error, symmetric=True))
if Z is not None: if Z is not None:
return Scatter3d(x=X, y=Y, z=Z, mode='markers', error_x=ErrorX(color=color, **error_kwargs or {}), showlegend=label is not None, marker=Marker(size='0'), name=label, **kwargs) return Scatter3d(x=X, y=Y, z=Z, mode='markers',
return Scatter(x=X, y=Y, mode='markers', error_x=ErrorX(color=color, **error_kwargs or {}), showlegend=label is not None, marker=Marker(size='0'), name=label, **kwargs) error_x=ErrorX(color=color, **error_kwargs or {}),
marker=Marker(size='0'), name=label,
showlegend=label is not None, **kwargs)
return Scatter(x=X, y=Y, mode='markers',
error_x=ErrorX(color=color, **error_kwargs or {}),
marker=Marker(size='0'), name=label,
showlegend=label is not None,
**kwargs)
def yerrorbar(self, ax, X, Y, error, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, error_kwargs=None, **kwargs): def yerrorbar(self, ax, X, Y, error, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, error_kwargs=None, **kwargs):
error_kwargs = error_kwargs or {} error_kwargs = error_kwargs or {}
if (error.shape[0] == 2) and (error.ndim == 2): if (error.shape[0] == 2) and (error.ndim == 2):
@ -195,8 +202,8 @@ class PlotlyPlots(AbstractPlottingLibrary):
if not 'showscale' in imshow_kwargs: if not 'showscale' in imshow_kwargs:
imshow_kwargs['showscale'] = False imshow_kwargs['showscale'] = False
return Heatmap(z=X, name=label, return Heatmap(z=X, name=label,
x0=extent[0], dx=float(extent[1]-extent[0])/X.shape[0], x0=extent[0], dx=float(extent[1]-extent[0])/(X.shape[0]-1),
y0=extent[2], dy=float(extent[3]-extent[2])/X.shape[1], y0=extent[2], dy=float(extent[3]-extent[2])/(X.shape[1]-1),
zmin=vmin, zmax=vmax, zmin=vmin, zmax=vmax,
showlegend=label is not None, showlegend=label is not None,
hoverinfo='z', hoverinfo='z',
@ -206,20 +213,26 @@ class PlotlyPlots(AbstractPlottingLibrary):
# TODO stream interaction? # TODO stream interaction?
super(PlotlyPlots, self).imshow_interact(ax, plot_function) super(PlotlyPlots, self).imshow_interact(ax, plot_function)
def annotation_heatmap(self, ax, X, annotation, extent=None, label=None, imshow_kwargs=None, **annotation_kwargs): def annotation_heatmap(self, ax, X, annotation, extent=None, label='Gradient', imshow_kwargs=None, **annotation_kwargs):
imshow = self.imshow(ax, X, extent, label, **imshow_kwargs) imshow_kwargs.setdefault('label', label)
imshow_kwargs.setdefault('showscale', True)
imshow = self.imshow(ax, X, extent, **imshow_kwargs)
X = X-X.min()
X /= X.max()/2.
X -= 1
x = np.linspace(extent[0], extent[1], X.shape[0]) x = np.linspace(extent[0], extent[1], X.shape[0])
y = np.linspace(extent[0], extent[1], X.shape[0]) y = np.linspace(extent[2], extent[3], X.shape[1])
annotations = Annotations() annotations = Annotations()
for n, row in enumerate(annotation): for n, row in enumerate(annotation):
for m, val in enumerate(row): for m, val in enumerate(row):
#var = z[n][m] var = X[n][m]
annotations.append( annotations.append(
Annotation( Annotation(
text=str(val), text=str(val),
x=x[m], y=y[n], x=x[m], y=y[n],
xref='x1', yref='y1', xref='x1', yref='y1',
font=dict(color='white' if val > 0.5 else 'black'), font=dict(color='white' if np.abs(var) > 0.8 else 'black', size=10),
opacity=.5,
showarrow=False)) showarrow=False))
return imshow, annotations return imshow, annotations
@ -228,7 +241,7 @@ class PlotlyPlots(AbstractPlottingLibrary):
def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs): def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs):
return Contour(x=X, y=Y, z=C, return Contour(x=X, y=Y, z=C,
ncontours=levels, contours=Contours(start=C.min(), end=C.max(), size=(C.max()-C.min())/levels), #ncontours=levels, contours=Contours(start=C.min(), end=C.max(), size=(C.max()-C.min())/levels),
name=label, **kwargs) name=label, **kwargs)
def surface(self, ax, X, Y, Z, color=None, label=None, **kwargs): def surface(self, ax, X, Y, Z, color=None, label=None, **kwargs):