Closed philipc2 closed 1 month ago
@ahuang11
Thanks for pointing me in the right direction with #1368
This should be ready for review.
Thanks! Took a quick skim; could you also add a line to Customization.ipynb to document it's available?
Thanks! Took a quick skim; could you also add a line to Customization.ipynb to document it's available?
Sure! Will run the pre-commit
too
I think op_options is missing a comma. Otherwise I think it looks good and I can take a deeper look/merge tomorrow!
Actually, the test seems to be failing:
def test_pixel_ratio(self, da2):
plot = da2.isel(other=0).hvplot(rasterize=True, pixel_ratio=4.0)
opts = Store.lookup_options('bokeh', plot, 'plot')
> assert opts.kwargs['pixel_ratio'] == 4.0
E KeyError: 'pixel_ratio'
Actually, the test seems to be failing:
def test_pixel_ratio(self, da2): plot = da2.isel(other=0).hvplot(rasterize=True, pixel_ratio=4.0) opts = Store.lookup_options('bokeh', plot, 'plot') > assert opts.kwargs['pixel_ratio'] == 4.0 E KeyError: 'pixel_ratio'
Do you have any suggestions on what I could do to fix this and/or how to best test this?
Thanks for updating customization! Can you also add to docstring?
For the failing test, can you see how datashading is asserted? (If there's a test for that)?
Thanks for updating customization! Can you also add to docstring?
For the failing test, can you see how datashading is asserted? (If there's a test for that)?
Maybe @maximlt can provide some input, I'm not sure the best way to move forward with the test.
Let me investigate a bit too.
Okay I found it
import xarray as xr
import hvplot.xarray
import xarray as xr
import holoviews as hv
ds = xr.open_dataset("sst.oisst.mon.ltm.1991-2020.nc")["sst"].isel(time=0)
p = ds.hvplot.image(rasterize=True, pixel_ratio=0.1)
assert p.callback.inputs[0].callback.operation.p["pixel_ratio"] == 0.1
For future reference, I looked up how other datashading tests were done
Maybe we should migrate the test over from testoptions.py to testoperations.py too.
Okay I found it
import xarray as xr import hvplot.xarray import xarray as xr import holoviews as hv ds = xr.open_dataset("sst.oisst.mon.ltm.1991-2020.nc")["sst"].isel(time=0) p = ds.hvplot.image(rasterize=True, pixel_ratio=0.1) assert p.callback.inputs[0].callback.operation.p["pixel_ratio"] == 0.1
For future reference, I looked up how other datashading tests were done
Maybe we should migrate the test over from testoptions.py to testoperations.py too.
Done! Moved them to testoperations.py
and updated the tests.
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 88.91%. Comparing base (
efeda78
) to head (fec2098
). Report is 3 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Useful for higher resolution screens where the PlotSize stream reports 'nominal' dimensions in pixels that do not match the physical pixels. For instance, setting pixel_ratio=2 can give better results on Retina displays.
My understanding is that currently Panel/HoloViews automatically pulls the right ratio based on the user display, so if that's the case this comment is misleading as e.g. users on Retina display will be led to set
pixel_ratio=2
while this is already done internally.Pasting a comment made by @philippjfr elsewhere:
That said I wonder if the pixel_ratio here should be relative to the display pixel ratio or simply override the existing pixel ratio as is done in the PR.
That may be the case, and I'm happy to rephrase it (took this word-for-word from the HoloViews source code)
@ahuang11 I was reviewing this PR again and read through the original issue (failed to do that previously). I'd like to make sure we're going in the right direction as exposing pixel_ratio
is not exactly what was suggested in the issue previously by @jbednar and discussed with @philippjfr and others. Well, one good reason for that is that pixel_ratio
was only added in HoloViews after that discussion happened https://github.com/holoviz/holoviews/pull/5288 🙃
Jim suggested 3 options, Philipp being happy with options 1 and 3.
1] hvPlot calls could accept an argument
rasterize_args
, a dictionary of key:value pairs that would be supplied as-is when hvPlot callsrasterize
, after its own arguments. Pros: Provides the full power ofhv.operation.datashader.rasterize()
, including all the various arguments shown above, within the hvPlot syntax. Cons: Full usage requires looking up the HoloViews documentation forrasterize
, at which point maybe people should just be using that operation directly.3] hvPlot calls could accept an argument
rasterize_factor
that is multiplicatively applied to the plot's native height and width to get the rasterization resolution. Pros: One new argument rather than two. Makes it simple to express "I want a lower resolution than usual" without fiddling with specific widths and heights. Cons: Only addresses this one use case.
I like option 1 too and somewhat disagree with the cons cited by Jim, it seems to be hvPlot could document the main keys that can be set via this dict argument. Pretty sure there are ways to type this dictionary so that users would get help from their IDE to populate it (well not yet in Jupyter).
Option 3 is what I think is implemented with pixel_ratio
? Except that in the issue there was a short discussion on finding a better name for rasterize_factor
and I doubt pixel_ratio
achieves that?
I would also like us to address this question before merging:
That said I wonder if the pixel_ratio here should be relative to the display pixel ratio or simply override the existing pixel ratio as is done in the PR.
@maximlt
I can create a separate issue on this topic if you'd like,
As for the design, I'm open to any considerations.
Depends how useful pixel_ratio is; if it's really useful I vote for 3; if not 1.
Option 1 is similar to colorbar_opts; I shy away from having to call colorbar_opts because I never remember the proper kwarg values.
there are ways to type this dictionary so that users would get help from their IDE to populate it
Sounds like a dataclass / pydantic model / parameterized
Depends how useful pixel_ratio is; if it's really useful I vote for 3; if not 1.
Option 1 is similar to colorbar_opts; I shy away from having to call colorbar_opts because I never remember the proper kwarg values.
there are ways to type this dictionary so that users would get help from their IDE to populate it
Sounds like a dataclass / pydantic model / parameterized
I've found pixel ratio to be extremely useful when paired with dynamic=False
for interactive plots.
pixel_ratio=8.0
)It's generally pretty intuitive for generating higher-resolution raster plots, while maintain the same plot size.
I'm in favor of having pixel_ratio exposed directly.
@philipc2 I took the liberty to push a commit with some changes to the docstring and re-ordering.
In the end, I decided that adding pixel_ratio
wasn't making hvPlot's API so much worse:
max_px
to configure dynspread, it's not in the signature or documented anywhere but is caught internally.But in general @ahuang11 I think we need to be careful when adding new parameters to hvPlot, because of the flat namespace this adds a cost to all users of hvPlot.
Thanks @philipc2 !
Closes #626
Overview
pixel_ratio
parameterExample Plots