Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HeatMap more general #849

Merged
merged 22 commits into from Jan 9, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+15 −18
Diff settings

Always

Just for now

Fixes for HeatMap implementations

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Sep 19, 2016
commit 69a979394ff5699dd8521557085ea07d47cb263b
Copy path View file
@@ -385,12 +385,6 @@ class HeatMap(Dataset, Element2D):
depth = 1

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jan 8, 2017

Contributor

I might have forgotten...what is this depth class attribute?

This comment has been minimized.

Copy link
@philippjfr

philippjfr Jan 8, 2017

Author Contributor

I think this may be wrong now, will have to look into it.

This comment has been minimized.

Copy link
@philippjfr

philippjfr Jan 8, 2017

Author Contributor

Wasn't needed at all in the end, removed it.



def __init__(self, data, **params):
super(HeatMap, self).__init__(data, **params)
shape = (len(self.dimension_values(1)), len(self.dimension_values(0)))
self.extents = (0., 0., shape[0], shape[1])


class Image(SheetCoordinateSystem, Raster):
"""
Image is the atomic unit as which 2D data is stored, along with
@@ -7,7 +7,7 @@
except ImportError:
LogColorMapper = None

from ...core.util import cartesian_product, is_nan
from ...core.util import cartesian_product, is_nan, unique_array
from ...element import Image, Raster, RGB
from ..renderer import SkipRendering
from ..util import map_colors, get_2d_aggregate
@@ -136,7 +136,7 @@ class HeatmapPlot(ColorbarPlot):
def _axes_props(self, plots, subplots, element, ranges):
dims = element.dimensions()
labels = self._get_axis_labels(dims)
xvals, yvals = [element.dimension_values(i, False)
xvals, yvals = [np.sort(unique_array(element.dimension_values(i, False)))
for i in range(2)]
if self.invert_yaxis: yvals = yvals[::-1]
plot_ranges = {'x_range': [str(x) for x in xvals],
@@ -145,17 +145,18 @@ def _axes_props(self, plots, subplots, element, ranges):

def get_data(self, element, ranges=None, empty=False):
x, y, z = element.dimensions(label=True)[:3]
aggregate = get_2d_aggregate(element)
aggregate = get_2d_aggregate(element).sort()
style = self.style[self.cyclic_index]
cmapper = self._get_colormapper(element.vdims[0], element, ranges, style)
if empty:
data = {x: [], y: [], z: [], 'color': []}
data = {x: [], y: [], z: []}
else:
zvals = aggregate.dimension_values(z)
xvals, yvals = [[str(v) for v in element.dimension_values(i)]
xvals, yvals = [[str(v) for v in aggregate.dimension_values(i)]
for i in range(2)]
data = {x: xvals, y: yvals, z: zvals}
if 'hover' in self.tools:

if 'hover' in self.tools+self.default_tools:
for vdim in element.vdims[1:]:
data[vdim.name] = ['' if is_nan(v) else v

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jan 8, 2017

Contributor

Wondering if an empty string really suggests NaN. 'NaN' would be explicit but might look noisy.

This comment has been minimized.

Copy link
@philippjfr

philippjfr Jan 8, 2017

Author Contributor

Good point, I'm now using masked arrays to represent the data, in matplotlib the NaNs are therefore represented by -, which might be better.

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jan 8, 2017

Contributor

Yes, I think - might be a good compromise.

for v in aggregate.dimension_values(vdim)]
@@ -8,7 +8,7 @@

from ...core import CompositeOverlay, Element
from ...core import traversal
from ...core.util import match_spec, max_range, unique_iterator
from ...core.util import match_spec, max_range, unique_iterator, unique_array
from ...element.raster import Image, Raster, RGB
from .element import ColorbarPlot, OverlayPlot
from .plot import MPLPlot, GridPlot
@@ -130,7 +130,7 @@ def _annotate_values(self, element):

def _compute_ticks(self, element, ranges):
xdim, ydim = element.kdims
dim1_keys, dim2_keys = [element.dimension_values(i, False)
dim1_keys, dim2_keys = [np.sort(unique_array(element.dimension_values(i, False)))
for i in range(2)]
num_x, num_y = len(dim1_keys), len(dim2_keys)
xpos = np.linspace(.5, num_x-0.5, num_x)
@@ -153,8 +153,9 @@ def init_artists(self, ax, plot_args, plot_kwargs):

def get_data(self, element, ranges, style):
_, style, axis_kwargs = super(HeatMapPlot, self).get_data(element, ranges, style)
shape = tuple(len(element.dimension_values(i)) for i in range(2))
aggregate = get_2d_aggregate(element)
shape = tuple(len(unique_array(element.dimension_values(i)))
for i in range(2))
aggregate = get_2d_aggregate(element).sort()
data = np.flipud(aggregate.dimension_values(2).reshape(shape[::-1]))
data = np.ma.array(data, mask=np.logical_not(np.isfinite(data)))
cmap_name = style.pop('cmap', None)
@@ -171,7 +172,8 @@ def update_handles(self, key, axis, element, ranges, style):
im = self.handles['artist']
data, style, axis_kwargs = self.get_data(element, ranges, style)
im.set_data(data[0])
im.set_extent((l, r, b, t))
shape = data[0].shape
im.set_extent((0, shape[1], 0, shape[0]))
im.set_clim((style['vmin'], style['vmax']))
if 'norm' in style:
im.norm = style['norm']
Copy path View file
@@ -489,7 +489,7 @@ def reduce_fn(x):
"""
Aggregation function to get the first non-zero value.
"""
values = x.values if pd and isinstance(pd.Series, values) else x
values = x.values if pd and isinstance(x, pd.Series) else x
for v in values:
if not is_nan(v):
return v
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.