Skip to content

Commit

Permalink
Fixed PlotSelector bug in RadialHeatMapPlot (#2621)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Apr 26, 2018
1 parent 3e5da1d commit 1e2398e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
21 changes: 15 additions & 6 deletions holoviews/plotting/bokeh/heatmap.py
Expand Up @@ -3,7 +3,9 @@

from bokeh.models import HoverTool, Span
from bokeh.models.glyphs import AnnularWedge

from ...core.util import is_nan, dimension_sanitizer
from ...core.spaces import HoloMap
from .element import (ColorbarPlot, CompositeElementPlot,
line_properties, fill_properties, text_properties)
from .util import mpl_to_bokeh
Expand Down Expand Up @@ -56,6 +58,7 @@ class HeatMapPlot(ColorbarPlot):

@classmethod
def is_radial(cls, heatmap):
heatmap = heatmap.last if isinstance(heatmap, HoloMap) else heatmap
opts = cls.lookup_options(heatmap, 'plot').options
return ((any(o in opts for o in ('start_angle', 'radius_inner', 'radius_outer'))
and not (opts.get('radial') == False)) or opts.get('radial', False))
Expand Down Expand Up @@ -264,7 +267,6 @@ def _get_bounds(mapper, values):
"""

array = np.array([mapper.get(x) for x in values])

return array[:, 0], array[:, 1]


Expand Down Expand Up @@ -509,10 +511,20 @@ def get_data(self, element, ranges, style):

# annular wedges
bins_ann = self._get_bins("radius", order_ann)
inner_radius, outer_radius = self._get_bounds(bins_ann, yvals)
if len(bins_ann):
inner_radius, outer_radius = self._get_bounds(bins_ann, yvals)
data_text_ann = self._get_ann_labels_data(order_ann, bins_ann)
else:
inner_radius, outer_radius = [], []
data_text_ann = dict(x=[], y=[], text=[], angle=[])

bins_seg = self._get_bins("angle", order_seg, True)
start_angle, end_angle = self._get_bounds(bins_seg, xvals)
if len(bins_seg):
start_angle, end_angle = self._get_bounds(bins_seg, xvals)
data_text_seg = self._get_seg_labels_data(order_seg, bins_seg)
else:
start_angle, end_angle = [], []
data_text_seg = dict(x=[], y=[], text=[], angle=[])

# create ColumnDataSources
data_annular = {"start_angle": start_angle,
Expand All @@ -528,9 +540,6 @@ def get_data(self, element, ranges, style):
for v in aggregate.dimension_values(vdim)]
data_annular[sanitized] = values

data_text_seg = self._get_seg_labels_data(order_seg, bins_seg)
data_text_ann = self._get_ann_labels_data(order_ann, bins_ann)

data_xmarks = self._get_xmarks_data(order_seg, bins_seg)
data_ymarks = self._get_ymarks_data(order_ann, bins_ann)

Expand Down
5 changes: 5 additions & 0 deletions holoviews/plotting/mpl/heatmap.py
Expand Up @@ -7,6 +7,7 @@
from matplotlib.collections import LineCollection, PatchCollection

from ...core.util import dimension_sanitizer, unique_array, is_nan
from ...core.spaces import HoloMap
from .element import ColorbarPlot
from .raster import RasterPlot

Expand Down Expand Up @@ -63,6 +64,7 @@ def get_extents(self, element, ranges):

@classmethod
def is_radial(cls, heatmap):
heatmap = heatmap.last if isinstance(heatmap, HoloMap) else heatmap
opts = cls.lookup_options(heatmap, 'plot').options
return ((any(o in opts for o in ('start_angle', 'radius_inner', 'radius_outer'))
and not (opts.get('radial') == False)) or opts.get('radial', False))
Expand Down Expand Up @@ -223,6 +225,9 @@ class RadialHeatMapPlot(ColorbarPlot):
radial = param.Boolean(default=True, doc="""
Whether the HeatMap should be radial""")

show_values = param.Boolean(default=False, doc="""
Whether to annotate each pixel with its value.""")

xmarks = param.Parameter(default=None, doc="""
Add separation lines between segments for better readability. By
default, does not show any separation lines. If parameter is of type
Expand Down
4 changes: 2 additions & 2 deletions tests/plotting/bokeh/testheatmapplot.py
Expand Up @@ -2,13 +2,13 @@

from holoviews.element import HeatMap, Points, Image

from .testplot import TestBokehPlot, bokeh_renderer

try:
from bokeh.models import FactorRange, HoverTool
except:
pass

from .testplot import TestBokehPlot, bokeh_renderer


class TestHeatMapPlot(TestBokehPlot):

Expand Down
16 changes: 15 additions & 1 deletion tests/plotting/bokeh/testradialheatmap.py
@@ -1,9 +1,17 @@
from __future__ import absolute_import

import numpy as np
from itertools import product

import numpy as np

from holoviews.core.spaces import HoloMap
from holoviews.element.raster import HeatMap

try:
from holoviews.plotting.bokeh import RadialHeatMapPlot
except:
pass

from .testplot import TestBokehPlot, bokeh_renderer


Expand Down Expand Up @@ -268,3 +276,9 @@ def test_plot_data_source(self):
self.assertEqual(list(source_ann["x"]), list(self.x))
self.assertEqual(list(source_ann["y"]), list(self.y))
self.assertEqual(list(source_ann["z"]), self.z)

def test_heatmap_holomap(self):
hm = HoloMap({'A': HeatMap(np.random.randint(0, 10, (100, 3))),
'B': HeatMap(np.random.randint(0, 10, (100, 3)))})
plot = bokeh_renderer.get_plot(hm.options(radial=True))
self.assertIsInstance(plot, RadialHeatMapPlot)
2 changes: 1 addition & 1 deletion tests/plotting/matplotlib/testheatmapplot.py
Expand Up @@ -5,7 +5,7 @@
from .testplot import TestMPLPlot, mpl_renderer


class TestLayoutPlot(TestMPLPlot):
class TestHeatMapPlot(TestMPLPlot):

def test_heatmap_invert_axes(self):
arr = np.array([[0, 1, 2], [3, 4, 5]])
Expand Down
11 changes: 11 additions & 0 deletions tests/plotting/matplotlib/testradialheatmap.py
Expand Up @@ -2,8 +2,14 @@

import numpy as np

from holoviews.core.spaces import HoloMap
from holoviews.element.raster import HeatMap

try:
from holoviews.plotting.mpl import RadialHeatMapPlot
except:
pass

from .testplot import TestMPLPlot, mpl_renderer


Expand Down Expand Up @@ -65,3 +71,8 @@ def test_get_data_yseparators(self):
for circle, r in zip(yseparators, [0.25, 0.375]):
self.assertEqual(circle.radius, r)

def test_heatmap_holomap(self):
hm = HoloMap({'A': HeatMap(np.random.randint(0, 10, (100, 3))),
'B': HeatMap(np.random.randint(0, 10, (100, 3)))})
plot = mpl_renderer.get_plot(hm.options(radial=True))
self.assertIsInstance(plot, RadialHeatMapPlot)

0 comments on commit 1e2398e

Please sign in to comment.