hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Setting individual color ranges for panels does not work when "adding" plots

Open tomchor opened this issue 4 years ago • 4 comments

ALL software version info

  • python = 3.7.9
  • hvplot = 0.7.0
  • bokeh = 2.2.3
  • jupyterlab = 2.2.9

Description of expected behavior and the observed behavior

When I plot DataArrays such as DA1.hvplot(title="DA1", clim=(0, 1)) + DA2.hvplot(title="DA2", clim=(0, 2)), thus explicitly giving each plot its own different color range, the color ranges are still the same.

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

from matplotlib import pyplot as plt
import xarray as xr
import numpy as np
import bokeh
import jupyterlab
import jupyter
import hvplot.xarray # To plot interactively with one line
import holoviews as hv

x_arr = np.linspace(0, 1)
x = xr.DataArray(x_arr, dims=['x'], coords=dict(x=x_arr))
y = xr.DataArray(x_arr, dims=['y'], coords=dict(y=x_arr))

DA1 = x*y
DA2 = x+y

(DA1.hvplot(title="DA1", clim=(0, 1)) + DA2.hvplot(title="DA2", clim=(0, 2))).cols(1)

Screenshots or screencasts of the bug in action

The code above produces the following output:

Screenshot from 2021-01-08 09-51-17

As you can see both plots have a color range of [0, 2], in spite of me explicitly setting one of them to a [0,1] range.

Am I missing something here or is this really a bug?

tomchor avatar Jan 08 '21 17:01 tomchor

Sorry for the slow response. HoloViews normalizes axis and color ranges across plots by defaults and this behavior is also enabled in hvPlot by default, to disable it you could set shared_axes=False.

philippjfr avatar Jan 14 '21 12:01 philippjfr

Thanks! That worked.

@philippjfr, A quick comment though: having the user manually set two distinct limits and then not see them applied definitely feels like a bug on the user's side. (I know because other people I asked about this also thought it was a bug.) So maybe it might be worth considering either disabling shared_axes when arguments that conflict with it are explicitly passed. Or at the very least issuing a warning to the user that shared_axes will overwrite those arguments.

Cheers!

tomchor avatar Jan 14 '21 16:01 tomchor

Yes, I absolutely agree with you. The main issue is that the underlying library has no way to independently control axis and colormapper linkage (apart from giving them distinct names) and disabling axis linking when you pass in clim is also unexpected. We'll have to separate the two options at the HoloViews level and then apply your suggestion.

philippjfr avatar Jan 14 '21 16:01 philippjfr

@philippjfr Isn't the solution to declare the dimension ranges on the returned HoloViews elements? That should override normalization. If not, that would be a HoloViews bug.

I'll label this as a bug as it does look like a bug at the user level even though it is expected when you know how hvplot and HoloViews interact.

jlstevens avatar Jan 25 '21 16:01 jlstevens