Skip to content

Commit

Permalink
Merge 286299c into 9fea0f9
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 18, 2016
2 parents 9fea0f9 + 286299c commit 4dcd0d3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
24 changes: 12 additions & 12 deletions holoviews/plotting/mpl/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,7 @@ def _compute_styles(self, element, ranges, style):
if cdim:
cs = element.dimension_values(self.color_index)
style['c'] = cs
if 'clim' not in style:
clims = ranges[cdim.name]
style.update(vmin=clims[0], vmax=clims[1])
self._norm_kwargs(element, ranges, style, cdim)
elif color:
style['c'] = color
style['edgecolors'] = style.pop('edgecolors', style.pop('edgecolor', 'none'))
Expand All @@ -566,8 +564,10 @@ def update_handles(self, key, axis, element, ranges, style):

cdim = element.get_dimension(self.color_index)
if cdim:
paths.set_clim(style['vmin'], style['vmax'])
paths.set_clim((style['vmin'], style['vmax']))
paths.set_array(style['c'])
if 'norm' in style:
paths.norm = style['norm']



Expand Down Expand Up @@ -912,7 +912,7 @@ def update_handles(self, key, axis, element, ranges, style):
return {'xticks': self.handles['xticks']}


class SpikesPlot(PathPlot):
class SpikesPlot(PathPlot, ColorbarPlot):

aspect = param.Parameter(default='square', doc="""
The aspect ratio mode of the plot. Allows setting an
Expand Down Expand Up @@ -949,13 +949,11 @@ def get_data(self, element, ranges, style):
if self.invert_axes:
data = [(line[0][::-1], line[1][::-1]) for line in data]

array, clim = None, None
cdim = element.get_dimension(self.color_index)
if cdim:
array = element.dimension_values(cdim)
clim = ranges[cdim.name]
style['array'] = array
style['clim'] = clim
style['array'] = element.dimension_values(cdim)
self._norm_kwargs(element, ranges, style, cdim)
style['clim'] = style.pop('vmin'), style.pop('vmax')
return (np.array(data),), style, {}


Expand All @@ -964,9 +962,11 @@ def update_handles(self, key, axis, element, ranges, style):
(data,), kwargs, axis_kwargs = self.get_data(element, ranges, style)
artist.set_paths(data)
artist.set_visible(style.get('visible', True))
if 'array' not in kwargs:
artist.set_clim(kwargs['clim'])
if 'array' in kwargs:
artist.set_clim((kwargs['vmin'], kwargs['vmax']))
artist.set_array(kwargs['array'])
if 'norm' in kwargs:
artist.norm = kwargs['norm']
return axis_kwargs


Expand Down
11 changes: 4 additions & 7 deletions holoviews/plotting/mpl/chart3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def update_handles(self, key, axis, element, ranges, style):
artist._offsets3d, style, _ = self.get_data(element, ranges, style)
cdim = element.get_dimension(self.color_index)
if cdim and 'cmap' in style:
clim = style['clim'] if 'clim' in style else ranges[cdim.name]
clim = style['vmin'], style['vmax']
cmap = cm.get_cmap(style['cmap'])
artist._facecolor3d = map_colors(style['c'], clim, cmap, hex=False)
if element.get_dimension(self.size_index):
Expand Down Expand Up @@ -176,8 +176,7 @@ def get_data(self, element, ranges, style):
rn, cn = mat.shape
l, b, zmin, r, t, zmax = self.get_extents(element, ranges)
r, c = np.mgrid[l:r:(r-l)/float(rn), b:t:(t-b)/float(cn)]
style['vmin'] = zmin
style['vmax'] = zmax
self._norm_kwargs(element, ranges, style, element.vdims[0])
return (r, c, mat), style, {}


Expand All @@ -194,10 +193,8 @@ class TrisurfacePlot(Plot3D):
style_opts = ['cmap', 'color', 'shade', 'linewidth', 'edgecolor']

def get_data(self, element, ranges, style):
dims = element.dimensions(label=True)
vrange = ranges[dims[2]]
style['vmin'] = vrange[0]
style['vmax'] = vrange[1]
dims = element.dimensions()
self._norm_kwargs(element, ranges, style, dims[2])
x, y, z = [element.dimension_values(d) for d in dims]
return (x, y, z), style, {}

Expand Down
13 changes: 7 additions & 6 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ class ColorbarPlot(ElementPlot):
set to None default matplotlib ticking behavior is
applied.""")

symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")

_colorbars = {}

def _adjust_cbar(self, cbar, label, dim):
Expand Down Expand Up @@ -568,16 +571,14 @@ def _draw_colorbar(self, artist, element, dim=None):



def _norm_kwargs(self, element, ranges, opts):
def _norm_kwargs(self, element, ranges, opts, vdim):
"""
Returns valid color normalization kwargs
to be passed to matplotlib plot function.
"""
norm = None
clim = opts.pop('clims', None)
if clim is None:
val_dim = [d.name for d in element.vdims][0]
clim = ranges.get(val_dim)
clim = ranges.get(vdim.name)
if self.symmetric:
clim = -np.abs(clim).max(), np.abs(clim).max()
if self.logz:
Expand All @@ -587,8 +588,8 @@ def _norm_kwargs(self, element, ranges, opts):
else:
norm = colors.LogNorm(vmin=clim[0], vmax=clim[1])
opts['norm'] = norm
opts['clim'] = clim

opts['vmin'] = clim[0]
opts['vmax'] = clim[1]


class LegendPlot(ElementPlot):
Expand Down
11 changes: 9 additions & 2 deletions holoviews/plotting/mpl/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def get_data(self, element, ranges, style):
for segments in element.data:
if segments.shape[0]:
polys.append(Polygon(segments))
style['clim'] = ranges[vdim.name]

if value is not None and np.isfinite(value):
self._norm_kwargs(element, ranges, style, vdim)
style['clim'] = style.pop('vmin'), style.pop('vmax')
style['array'] = np.array([value]*len(polys))
return (polys,), style, {}

Expand All @@ -68,10 +70,15 @@ def init_artists(self, ax, plot_args, plot_kwargs):


def update_handles(self, key, axis, element, ranges, style):
value = element.level
vdim = element.vdims[0]
collection = self.handles['artist']
if any(not np.array_equal(data, poly.get_xy()) for data, poly in
zip(element.data, self.handles['polys'])):
return super(PolygonPlot, self).update_handles(key, axis, element, ranges, style)
elif value is not None and np.isfinite(value):
self._norm_kwargs(element, ranges, style, vdim)
collection.set_array(np.array([value]*len(element.data)))
collection.set_clim(ranges[vdim.name])
collection.set_clim((style['vmin'], style['vmax']))
if 'norm' in style:
collection.norm = style['norm']
18 changes: 7 additions & 11 deletions holoviews/plotting/mpl/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class RasterPlot(ColorbarPlot):
situate_axes = param.Boolean(default=False, doc="""
Whether to situate the image relative to other plots. """)

symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")

style_opts = ['alpha', 'cmap', 'interpolation', 'visible',
'filterrad', 'clims', 'norm']

Expand Down Expand Up @@ -71,7 +68,8 @@ def get_data(self, element, ranges, style):

if isinstance(element, RGB):
data = element.rgb.data
self._norm_kwargs(element, ranges, style)
vdim = element.vdims[0]
self._norm_kwargs(element, ranges, style, vdim)
style['extent'] = [l, r, b, t]

return [data], style, {'xticks': xticks, 'yticks': yticks}
Expand All @@ -88,7 +86,7 @@ def update_handles(self, key, axis, element, ranges, style):
l, r, b, t = style['extent']
im.set_data(data[0])
im.set_extent((l, r, b, t))
im.set_clim(style['clim'])
im.set_clim((style['vmin'], style['vmax']))
if 'norm' in style:
im.norm = style['norm']

Expand Down Expand Up @@ -171,7 +169,7 @@ def update_handles(self, key, axis, element, ranges, style):
l, r, b, t = style['extent']
im.set_data(data[0])
im.set_extent((l, r, b, t))
im.set_clim(style['clim'])
im.set_clim((style['vmin'], style['vmax']))
if 'norm' in style:
im.norm = style['norm']

Expand All @@ -190,9 +188,6 @@ def update_handles(self, key, axis, element, ranges, style):

class QuadMeshPlot(ColorbarPlot):

symmetric = param.Boolean(default=False, doc="""
Whether to make the colormap symmetric around zero.""")

style_opts = ['alpha', 'cmap', 'clim', 'edgecolors', 'norm', 'shading',
'linestyles', 'linewidths', 'hatch', 'visible']

Expand All @@ -201,7 +196,8 @@ def get_data(self, element, ranges, style):
mask=np.logical_not(np.isfinite(element.data[2])))
cmesh_data = list(element.data[:2]) + [data]
style['locs'] = np.concatenate(element.data[:2])
self._norm_kwargs(element, ranges, style)
vdim = element.vdims[0]
self._norm_kwargs(element, ranges, style, vdim)
return tuple(cmesh_data), style, {}


Expand All @@ -221,7 +217,7 @@ def update_handles(self, key, axis, element, ranges, style):
else:
data, style, axis_kwargs = self.get_data(element, ranges, style)
cmesh.set_array(data[-1])
cmesh.set_clim(style['clim'])
im.set_clim((style['vmin'], style['vmax']))
if 'norm' in style:
cmesh.norm = style['norm']
return axis_kwargs
Expand Down

0 comments on commit 4dcd0d3

Please sign in to comment.