question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

width/height not taken into account in a `regrid` operation with the Bokeh backend

See original GitHub issue

The regrid operation does not seem to take into account width and height when using the Bokeh backend. The example shows that it does work with the Matplotlib backend. Notice in the GIF how for a very short moment the Bokeh plot seems to have the right grid, and then updates to the original image resolution apparently.

issue_holoviews_regrid

Here’s the full code:

import numpy as np, holoviews as hv
from holoviews.operation.datashader import regrid
hv.extension('bokeh', 'matplotlib')

arr = np.random.rand(200, 200)
img = hv.Image(arr)
regrid(img, width=10, height=10)

hv.output(backend='matplotlib')
regrid(img, width=10, height=10)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
maximltcommented, Nov 14, 2022

We have spent some time looking into that. The base ResamplingOperation - from which regrid, rasterize and others inherit - has parameters width and height and also sets up by default the RangeXY and PlotSize streams.

https://github.com/holoviz/holoviews/blob/e5224c6a278829ca6165ac04b36da6d5f55825cf/holoviews/operation/datashader.py#L73-L77

https://github.com/holoviz/holoviews/blob/e5224c6a278829ca6165ac04b36da6d5f55825cf/holoviews/operation/datashader.py#L105-L107

The parameters of the PlotSize streams are also called width and height.

https://github.com/holoviz/holoviews/blob/e5224c6a278829ca6165ac04b36da6d5f55825cf/holoviews/streams.py#L1424-L1431

Which means that when the PlotSize stream is triggered - after rendering - the regrid operation is called again this time with width and height obtained from the stream and as such different from the values provided to regrid by the user.

I’ll offer now solutions for different use cases and ask some questions for how to improve the current state:

  1. you want regridding to be based on the number of pixels your plot output uses, let HoloViews compute it automatically with regrid(img)
  2. you want to perform static/fixed regridding, i.e. on zoom/pan events no regridding should be performed again, then use dynamic=False: regrid(img, width=10, height=10, dynamic=False)
  3. you want a mix of 1 and 2 with regridding being performed on zoom/pan events but with dimensions that you provide instead of dimensions being inferred by HoloViews (what this issue is about), override streams so that the operation doesn’t set the PlotSize stream: regrid(img, width=10, height=10, streams=[hv.streams.RangeXY])

3 in the list above feels more like a workaround for a bug rather than a clean solution. We played around with a potential bug fix that consists in removing the PlotSize stream if width or height is provided:

class ResamplingOperation(LinkableOperation):

    ...

    def __call__(self, *args, **kwargs):
        if 'width' in kwargs or 'height' in kwargs:
            print('warning: dropping PlotSize stream using explicit width/height')
            # What if values specified by kwargs are supposed to be the initial stream values?
            if PlotSize in self.streams and isinstance(self.streams, list):  # Also needs to handle dict
                streams = self.streams.copy()
                streams.remove(PlotSize)
                kwargs['streams'] = streams
        return super().__call__(*args, **kwargs)

    ...

We’d really appreciate to hear your thoughts on that @philippjfr:

  • Did we identify the right problem? I.e. that the operation and stream share the same namespace which means they end up being linked? Is that by design?
  • Are we heading in the right direction with our approach to fix this?

cc @jlstevens @Hoxbro @droumis

0reactions
philippjfrcommented, Nov 18, 2022

Seems reasonable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releases — HoloViews v1.15.3
Take account of labeled dimension in Bokeh plotting classes (#5404) ... In future, HoloViews will not allow non-string values for pandas DataFrame column ......
Read more >
Bar plots in holoviews with bokeh backend do not overlay
in plotly the legend should be replaced by name of the overlayed objects - how to do that in plotly aspect, width, height...
Read more >
holoviews Changelog - pyup.io
Take account of labeled dimension in Bokeh plotting classes ... In future, HoloViews will not allow non-string values for pandas DataFrame column names....
Read more >
Fast Remote Image Viewer - HoloViews - HoloViz Discourse
On start, I'm loading the image plots into a dictionary (and cache) and feeding ... from holoviews.operation.datashader import regrid hv.extension('bokeh') ...
Read more >
REST API: db/completion no output when one folder is paused ...
width/height not taken into account in a `regrid ` operation with the Bokeh backend, 1, 2022-05-16, 2022-08-19. Paladin Class has wrong cost increase ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found