Skip to content

Wrong colors when using method='datashader' #311

Closed

Description

@LucaMarconato

When method=datashader is used the colors that are produced are wrong. Strangely the colorbar is correct. Initially I though this was due to the choice of the agg function when each pixel of the rasterized image was overlapping multiple elements. But since this problem appears also for large bins, which span several pixels, and since no border effect is observed, I believe that the problem lies elsewhere.

Code to reproduce.

##
import spatialdata_plot
from spatialdata import read_zarr, bounding_box_query
import matplotlib.pyplot as plt

f = 'spatialdata-sandbox/visium_hd_3.0.0_io/data.zarr'

sdata = read_zarr(f)
sdata

for table in sdata.tables.values():
    table.var_names_make_unique()

##
crop = lambda x: bounding_box_query(
    x, min_coordinate=[5000, 7000], max_coordinate=[10000, 12000], axes=("x", "y"), target_coordinate_system="global"
)
gene_name = "AA986860"

##
crop(sdata).pl.render_shapes('Visium_HD_Mouse_Small_Intestine_square_016um', color=gene_name).pl.show(coordinate_systems='global')
plt.show()

##
crop(sdata).pl.render_shapes('Visium_HD_Mouse_Small_Intestine_square_016um', color=gene_name, method='datashader').pl.show(coordinate_systems='global')
plt.show()

Activity

  1. LucaMarconato commented on Jul 18, 2024

    @LucaMarconato
    MemberAuthor

    This is the first plot, the correct one (method='matplotlib').
    image

    This is the second plot, the wrong one (method='datashader').
    image

  2. Sonja-Stockhaus commented on Jul 19, 2024

    @Sonja-Stockhaus
    Collaborator

    Thanks @LucaMarconato! The aggregation is correct, but shade() uses an equi-width histogram for coloring per default, while we want the linear version. Now it looks like this using datashader

    grafik

  3. linked a pull request that will close this issuedatashader speedup and bugfixes #309on Jul 19, 2024
  4. LucaMarconato commented on Jul 19, 2024

    @LucaMarconato
    MemberAuthor

    Thanks for checking into this!

  5. LucaMarconato commented on Aug 12, 2024

    @LucaMarconato
    MemberAuthor

    Update: different aggregation functions require different colorbars, we are working into this.

  6. added this to the v0.2.7 milestone on Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions