Skip to content

Inconsistent behaviour with hv.Image hv.QuadMesh when plotting in logspace #6714

@zhiihan

Description

@zhiihan

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Software Version Info
bokeh = 3.8.0
holoviews = 1.21.0
numpy = 1.26.4
python = 3.10.19

Description of expected behavior and the observed behavior

Hi, I am trying to generate some plots in logspace. My expectation is that if I have data in logspace and my axes are in logspace, then I should be able to avoid rtol or anything when using hv.Image.

A workaround is to plot the exponent of the data: i.e.

hv.Image
import holoviews as hv
import numpy as np

hv.extension('bokeh')

npoints = 50

x = np.linspace(1, 10, 5)
y = np.logspace(0.1, 2, npoints)
transformed_y = np.log10(y)

data = np.random.rand(npoints, 5)
img = hv.Image((x, transformed_y, data), kdims=['x', 'y']).opts(
    colorbar=True,
    ylim=(0.1, 2)
)
img

But I think this should work out of the box if the user uses logy = True, no? i.e. this is the plot I expect to see (note that the y axes is linear, not logspace). I now run two tests for when using log axes, i.e. logy = True when y is logspace data.

Image

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

Test 1: hv.Image with npoints = 50, 5

import holoviews as hv
import numpy as np

hv.extension('bokeh')

npoints = 50 # change this to 5 later

x = np.linspace(1, 10, 5)
y = np.logspace(0.1, 2, npoints)

data = np.random.rand(npoints, 5)

img = hv.Image((x, y, data), kdims=['x', 'y']).opts(
    logy=True,
    colorbar=True,
    ylim=(1, 100)
)
img

when npoints = 50, we see the expected plot logspace but with a warning. When npoints = 5, we get a blank plot.
Furthermore, when y has negative exponents, i.e. y = np.logspace(-4, -2, npoints), even for npoints = 50, we also get a blank plot.

Image

Test 2: hv.QuadMesh

Here, at low npoints=5 count, we use hv.QuadMesh. The bottom is missing and a white strip appears.

import holoviews as hv
import numpy as np

hv.extension('bokeh')

npoints = 5

x = np.linspace(1, 10, 5)
y = np.logspace(-5, -1, npoints)

data = np.random.rand(npoints, 5)

img = hv.QuadMesh((x, y, data), kdims=['x', 'y']).opts(
    logy=True,
    colorbar=True,
    ylim=(1e-5, 1e-1)
)
img

Observed:

Image

Expected: (generated with transformed_y)

Image

Code that generates the expected plot:

import holoviews as hv
import numpy as np

hv.extension('bokeh')

npoints = 5

x = np.linspace(1, 10, 5)
y = np.logspace(-5, -1, npoints)

data = np.random.rand(npoints, 5)

img = hv.QuadMesh((x, y, data), kdims=['x', 'y']).opts(
    logy=True,
    colorbar=True,
    ylim=(1e-5, 1e-1)
)
img

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

  • I may be interested in making a pull request to address this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions