Cannot fix aspect ratio and remove padding simultaneously
See original GitHub issueI am trying to plot an image
using the xarray accessor, but can’t seem to be able to specify the aspect ratio and also remove padding simultaneously.
Demonstration:
import xarray as xr
import hvplot.xarray # noqa
air_ds = xr.tutorial.open_dataset('air_temperature').load()
air2d = air_ds.air.sel(time='2013-06-01 12:00')
default behaviour
air2d.hvplot.image()
air2d.hvplot.image().opts(data_aspect=True)
air2d.hvplot.image(padding=0)
air2d.hvplot.image(padding=0).opts(data_aspect=True)
I would have expected the last figure not to have any padding at the sides.
This shows that I can’t currently choose my axis to have the same aspect ratio as the data, and also remove all padding simultaneously. I don’t know whether this is a bokeh problem or a hvplot problem, but I thought I would raise it here first.
I also tried setting xlim
but that did not remove the padding either.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Maintain aspect ratio of div but fill screen width and height ...
Use the new CSS viewport units vw and vh (viewport width / viewport height). FIDDLE. Resize vertically and horizontally and you'll see that ......
Read more >aspect-ratio
unset : Removes the current aspect ratio from the element. It can take two values. This property can take two values at the...
Read more >Aspect Ratios in CSS are a Hack
Technique #1: Vertical Padding ... A (hopefully) well known and longstanding hack to faking aspect ratios on the web is to abuse the...
Read more >Responsive iframes with the CSS aspect-ratio property
Today, I want to show you can use a few lines of CSS to make your embedded iframes fully responsive. Let's dig in!...
Read more >Avoiding <img> layout shifts: aspect-ratio vs width & height ...
In this case, the two images have different aspect ratios. Chrome and Safari use the correct width and height depending on which source...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Two things that might work:
air2d.hvplot.image(data_aspect=True)
frame_width
/frame_height
to match the ratio of data_aspect.Oh! I didn’t spot that in your response! Ah, this is an interaction between hvPlot and HoloViews, then. I think hvPlot sets the height and width when it hands things over to HoloViews, and once that’s happened, HoloViews sees
data_aspect
,height
, andwidth
as all having been specified by the user, and thus tries to achieve all three instructions. Whendata_aspect
is given to hvPlot directly, it can take effect before height and width are given values in hvPlot.So it’s great that there is a reasonable way to achieve the desired behavior, but it’s not at all a good situation, because having
data_aspect
behave so differently depending on whether it’s passed to hvPlot or HoloViews is very tricky and subtle. I think I’ve noticed similar issues withresponsive
andsizing_mode
, i.e. things where it matters whether a height or width has been set explicitly by the user. Definitely a topic for someone who knows that interface between hvPlot and HoloViews better than I do to address!