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

Support plots that use by with rasterize with hv.ImageStack #1132

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also have a version check, but let us ignore it if all tests pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep for us it works well but sometimes distros that re-package our tools complain about this kind of stuff (and probably just patch things).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll add a check in another PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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