Skip to content

Commit

Permalink
Support plots that use by with rasterize with hv.ImageStack (#1132)
Browse files Browse the repository at this point in the history
* WIP overlaying rasterized

* Clean up

* Add rasterize to check for categorical

* Add test

* Add version check

* Update hvplot/converter.py

Co-authored-by: Simon Høxbro Hansen <simon.hansen@me.com>

---------

Co-authored-by: Simon Høxbro Hansen <simon.hansen@me.com>
  • Loading branch information
ahuang11 and hoxbro authored Sep 19, 2023
1 parent 30999e8 commit 3700ae2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def __init__(
symmetric = self._process_symmetric(symmetric, clim, check_symmetric_max)
if self._style_opts.get('cmap') is None:
# Default to categorical camp if we detect categorical shading
if (self.datashade and (self.aggregator is None or 'count_cat' in str(self.aggregator)) and
if ((self.datashade or self.rasterize) and (self.aggregator is None or 'count_cat' in str(self.aggregator)) and
((self.by and not self.subplots) or
(isinstance(self.y, list) or (self.y is None and len(set(self.variables) - set(self.indexes)) > 1)))):
self._style_opts['cmap'] = self._default_cmaps['categorical']
Expand Down Expand Up @@ -1330,7 +1330,10 @@ def method_wrapper(ds, x, y):
opts['rescale_discrete_levels'] = self._plot_opts['rescale_discrete_levels']
else:
operation = rasterize
eltype = 'Image'
if Version(hv.__version__) < Version('1.18.0a1'):
eltype = 'Image'
else:
eltype = 'ImageStack' if self.by else 'Image'
if 'cmap' in self._style_opts:
style['cmap'] = self._style_opts['cmap']
if self._dim_ranges.get('c', (None, None)) != (None, None):
Expand Down
8 changes: 7 additions & 1 deletion hvplot/tests/testoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from unittest import SkipTest
from parameterized import parameterized

import colorcet as cc
import hvplot.pandas # noqa
import numpy as np
import pandas as pd

from holoviews import Store
from holoviews.element import Image, QuadMesh
from holoviews.element import Image, QuadMesh, ImageStack
from holoviews.element.comparison import ComparisonTestCase
from hvplot.converter import HoloViewsConverter

Expand Down Expand Up @@ -194,6 +195,11 @@ def test_datashade_rescale_discrete_levels_default_True(self):
actual = plot.callback.inputs[0].callback.operation.p['rescale_discrete_levels']
assert actual is expected

def test_rasterize_by(self):
expected = 'category'
plot = self.df.hvplot(x='x', y='y', by=expected, rasterize=True, dynamic=False)
assert isinstance(plot, ImageStack)
assert plot.opts["cmap"] == cc.palette['glasbey_category10']

class TestChart2D(ComparisonTestCase):

Expand Down

0 comments on commit 3700ae2

Please sign in to comment.