hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Odd behavior with invert_yaxis, invert_xaxis

Open vlvalenti opened this issue 3 years ago • 1 comments

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc) panel: 0.12.4 param: 1.12.0 jupyterlab: 3.0.16 holoviews: 1.14.7
hvplot: 0.7.2 bokeh: 2.4.2

Description of expected behavior and the observed behavior

Expected:

  1. that the image hvplot would invert y and x axis when triggered
  2. inverting the axis would not affect view of plot

Observed:

  1. image plot disappears when either x or y axis is inverted
  2. view of both plots continually zooms in each time the axis is inverted

Complete, minimal, self-contained example code that reproduces the issue

import holoviews as hv
import panel as pn
import param
import numpy as np
import hvplot.xarray
import xarray as xr
hv.extension('bokeh', logo=False)

data = xr.tutorial.open_dataset('air_temperature').air

class Viewer(param.Parameterized):
    tabs_switch = param.Boolean(True, label="Toggle Tabs")
    cmap = param.Selector(objects=["rainbow", "fire", "bwr"])
    invert_yaxis = pn.widgets.Checkbox(value=False, name='Invert y axis')
    invert_xaxis = pn.widgets.Checkbox(value=False, name='Invert x axis')

    def __init__(self, **params):
        super().__init__(**params)
        
        self.opts = dict(cmap=self.param.cmap, invert_yaxis=self.invert_yaxis, invert_xaxis=self.invert_xaxis, padding=0, 
                        height=800, width=800)

        self.plot = pn.pane.HoloViews()
        
        self.make_layout()
        
        self.column = pn.Column(
            pn.WidgetBox(pn.Param(self.param, parameters=["tabs_switch", "cmap"]), self.invert_yaxis, self.invert_xaxis),
            self.plot
        )
        
    def create_image(self):
        x, y = np.mgrid[-50:51, -50:51] * 0.05
        img = data.hvplot(x='lon', y='lat').opts(colorbar=True)
        return img

    def create_contours(self):
        img = self.create_image()
        contours = hv.operation.contours(img, levels=10, filled=True)
        return contours

    @param.depends("tabs_switch", watch=True)
    def make_layout(self):
        image = self.create_image()
        contours = self.create_contours()
        self.plot.object = hv.Layout(image.apply.opts(**self.opts) +\
                                     contours.apply.opts(**self.opts)).opts(tabs=self.tabs_switch)

v = Viewer()
se = pn.serve(v.column)

Screenshots or screencasts of the bug in action

https://user-images.githubusercontent.com/71399442/154738786-650043a9-a525-4421-9503-0cfe6c2f57b8.mov

Appears to be a bug to me. Thanks

vlvalenti avatar Feb 18 '22 18:02 vlvalenti

It looks like a bug, we need to investigate this further. Thanks!

MridulS avatar Feb 28 '22 16:02 MridulS

For some context on this - I am running into the same thing. The image doesn't necessarily disappear, but actually shifts the image instead of flipping it:

Screenshot 2023-07-05 at 2 35 09 PM

kgullikson-sc avatar Jul 05 '23 19:07 kgullikson-sc