Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with set_zero_in_cmap_to_transparent Function Not Making Zero Values Transparent in Spatial Data Plotting #376

Open
lisch7 opened this issue Oct 21, 2024 · 7 comments

Comments

@lisch7
Copy link

lisch7 commented Oct 21, 2024

Issue Description

I am experiencing an issue with the set_zero_in_cmap_to_transparent function. According to the documentation, using this function should set the positions in the data with a value of 0 to be transparent. However, I found that instead of becoming transparent, these positions turn white after executing the function.

Code

Output without set_zero_in_cmap_to_transparent functions:

sdata_small.pl.render_images("_full_image").pl.render_shapes(
    "_square_008um",color="CD3D", cmap="viridis").pl.show(coordinate_systems="global", title="bin_size=8µm", figsize=(5, 5))

Image

Output with set_zero_in_cmap_to_transparent functions:

from spatialdata_plot.pl.utils import set_zero_in_cmap_to_transparent

# let's display the areas where no expression is detected as transparent
new_cmap = set_zero_in_cmap_to_transparent(cmap="viridis")
new_cmap

Image

sdata_small.pl.render_images("_full_image").pl.render_shapes(
    "_square_008um",color="CD3D", cmap=new_cmap).pl.show(coordinate_systems="global", title="bin_size=8µm", figsize=(5, 5))

Image

Environment Information

conda list
# packages in environment at /data2/data2_mailab003/biosoft/miniconda3/envs/spatialdata:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main    defaults
_openmp_mutex             5.1                       1_gnu    defaults
aiobotocore               2.5.4                    pypi_0    pypi
aiohappyeyeballs          2.4.3                    pypi_0    pypi
aiohttp                   3.10.10                  pypi_0    pypi
aioitertools              0.12.0                   pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
alabaster                 0.7.16                   pypi_0    pypi
anndata                   0.10.9                   pypi_0    pypi
annotated-types           0.7.0                    pypi_0    pypi
app-model                 0.3.0                    pypi_0    pypi
appdirs                   1.4.4                    pypi_0    pypi
array-api-compat          1.9                      pypi_0    pypi
asciitree                 0.3.3                    pypi_0    pypi
asttokens                 2.4.1                    pypi_0    pypi
async-timeout             4.0.3                    pypi_0    pypi
attrs                     24.2.0                   pypi_0    pypi
babel                     2.16.0                   pypi_0    pypi
botocore                  1.31.17                  pypi_0    pypi
build                     1.2.2.post1              pypi_0    pypi
ca-certificates           2024.9.24            h06a4308_0    defaults
cachey                    0.2.1                    pypi_0    pypi
certifi                   2024.8.30                pypi_0    pypi
charset-normalizer        3.4.0                    pypi_0    pypi
click                     8.1.7                    pypi_0    pypi
cloudpickle               3.1.0                    pypi_0    pypi
colorcet                  3.1.0                    pypi_0    pypi
comm                      0.2.2                    pypi_0    pypi
contourpy                 1.3.0                    pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
dask                      2024.8.0                 pypi_0    pypi
dask-expr                 1.1.10                   pypi_0    pypi
dask-image                2024.5.3                 pypi_0    pypi
datashader                0.16.3                   pypi_0    pypi
debugpy                   1.8.7                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
distributed               2024.8.0                 pypi_0    pypi
docrep                    0.3.2                    pypi_0    pypi
docstring-parser          0.16                     pypi_0    pypi
docutils                  0.21.2                   pypi_0    pypi
exceptiongroup            1.2.2                    pypi_0    pypi
executing                 2.1.0                    pypi_0    pypi
fasteners                 0.19                     pypi_0    pypi
fcsparser                 0.2.8                    pypi_0    pypi
flexcache                 0.3                      pypi_0    pypi
flexparser                0.3.1                    pypi_0    pypi
fonttools                 4.54.1                   pypi_0    pypi
freetype-py               2.5.1                    pypi_0    pypi
frozenlist                1.4.1                    pypi_0    pypi
fsspec                    2023.6.0                 pypi_0    pypi
geopandas                 1.0.1                    pypi_0    pypi
get-annotations           0.1.2                    pypi_0    pypi
h5py                      3.12.1                   pypi_0    pypi
heapdict                  1.0.1                    pypi_0    pypi
hsluv                     5.0.4                    pypi_0    pypi
idna                      3.10                     pypi_0    pypi
igraph                    0.11.6                   pypi_0    pypi
imagecodecs               2024.9.22                pypi_0    pypi
imageio                   2.36.0                   pypi_0    pypi
imagesize                 1.4.1                    pypi_0    pypi
importlib-metadata        8.5.0                    pypi_0    pypi
importlib-resources       6.4.5                    pypi_0    pypi
in-n-out                  0.2.1                    pypi_0    pypi
inflect                   7.4.0                    pypi_0    pypi
ipykernel                 6.29.5                   pypi_0    pypi
ipython                   8.18.1                   pypi_0    pypi
jedi                      0.19.1                   pypi_0    pypi
jinja2                    3.1.4                    pypi_0    pypi
jmespath                  1.0.1                    pypi_0    pypi
joblib                    1.4.2                    pypi_0    pypi
jsonschema                4.23.0                   pypi_0    pypi
jsonschema-specifications 2024.10.1                pypi_0    pypi
jupyter-client            8.6.3                    pypi_0    pypi
jupyter-core              5.7.2                    pypi_0    pypi
kiwisolver                1.4.7                    pypi_0    pypi
lamin-utils               0.13.7                   pypi_0    pypi
lazy-loader               0.4                      pypi_0    pypi
ld_impl_linux-64          2.40                 h12ee557_0    defaults
legacy-api-wrap           1.4                      pypi_0    pypi
leidenalg                 0.10.2                   pypi_0    pypi
libffi                    3.4.4                h6a678d5_1    defaults
libgcc-ng                 11.2.0               h1234567_1    defaults
libgomp                   11.2.0               h1234567_1    defaults
libstdcxx-ng              11.2.0               h1234567_1    defaults
llvmlite                  0.43.0                   pypi_0    pypi
locket                    1.0.0                    pypi_0    pypi
loguru                    0.7.2                    pypi_0    pypi
louvain                   0.8.2                    pypi_0    pypi
magicgui                  0.9.1                    pypi_0    pypi
markdown-it-py            3.0.0                    pypi_0    pypi
markupsafe                3.0.1                    pypi_0    pypi
matplotlib                3.9.2                    pypi_0    pypi
matplotlib-inline         0.1.7                    pypi_0    pypi
matplotlib-scalebar       0.8.1                    pypi_0    pypi
mdurl                     0.1.2                    pypi_0    pypi
more-itertools            10.5.0                   pypi_0    pypi
msgpack                   1.1.0                    pypi_0    pypi
multidict                 6.1.0                    pypi_0    pypi
multipledispatch          1.0.0                    pypi_0    pypi
multiscale-spatial-image  1.0.1                    pypi_0    pypi
napari                    0.5.4                    pypi_0    pypi
napari-console            0.1.0                    pypi_0    pypi
napari-matplotlib         2.0.1                    pypi_0    pypi
napari-plugin-engine      0.2.0                    pypi_0    pypi
napari-spatialdata        0.5.3                    pypi_0    pypi
napari-svg                0.2.0                    pypi_0    pypi
natsort                   8.4.0                    pypi_0    pypi
ncurses                   6.4                  h6a678d5_0    defaults
nest-asyncio              1.6.0                    pypi_0    pypi
networkx                  3.2.1                    pypi_0    pypi
npe2                      0.7.7                    pypi_0    pypi
numba                     0.60.0                   pypi_0    pypi
numcodecs                 0.12.1                   pypi_0    pypi
numpy                     1.26.4                   pypi_0    pypi
numpydoc                  1.8.0                    pypi_0    pypi
ome-zarr                  0.9.0                    pypi_0    pypi
omnipath                  1.0.8                    pypi_0    pypi
openssl                   3.0.15               h5eee18b_0    defaults
packaging                 24.1                     pypi_0    pypi
pandas                    2.2.3                    pypi_0    pypi
param                     2.1.1                    pypi_0    pypi
parso                     0.8.4                    pypi_0    pypi
partd                     1.4.2                    pypi_0    pypi
patsy                     0.5.6                    pypi_0    pypi
pexpect                   4.9.0                    pypi_0    pypi
pillow                    11.0.0                   pypi_0    pypi
pims                      0.7                      pypi_0    pypi
pint                      0.24.3                   pypi_0    pypi
pip                       24.2             py39h06a4308_0    defaults
platformdirs              4.3.6                    pypi_0    pypi
pooch                     1.8.2                    pypi_0    pypi
prompt-toolkit            3.0.48                   pypi_0    pypi
propcache                 0.2.0                    pypi_0    pypi
psutil                    6.0.0                    pypi_0    pypi
psygnal                   0.11.1                   pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.3                    pypi_0    pypi
pyarrow                   17.0.0                   pypi_0    pypi
pyconify                  0.1.6                    pypi_0    pypi
pyct                      0.5.0                    pypi_0    pypi
pydantic                  2.9.2                    pypi_0    pypi
pydantic-compat           0.1.2                    pypi_0    pypi
pydantic-core             2.23.4                   pypi_0    pypi
pygments                  2.18.0                   pypi_0    pypi
pynndescent               0.5.13                   pypi_0    pypi
pyogrio                   0.10.0                   pypi_0    pypi
pyopengl                  3.1.7                    pypi_0    pypi
pyparsing                 3.2.0                    pypi_0    pypi
pyproj                    3.6.1                    pypi_0    pypi
pyproject-hooks           1.2.0                    pypi_0    pypi
pyqt5                     5.15.11                  pypi_0    pypi
pyqt5-qt5                 5.15.15                  pypi_0    pypi
pyqt5-sip                 12.15.0                  pypi_0    pypi
python                    3.9.20               he870216_1    defaults
python-dateutil           2.9.0.post0              pypi_0    pypi
pytz                      2024.2                   pypi_0    pypi
pyyaml                    6.0.2                    pypi_0    pypi
pyzmq                     26.2.0                   pypi_0    pypi
qtconsole                 5.6.0                    pypi_0    pypi
qtpy                      2.4.1                    pypi_0    pypi
readfcs                   1.1.8                    pypi_0    pypi
readline                  8.2                  h5eee18b_0    defaults
referencing               0.35.1                   pypi_0    pypi
requests                  2.32.3                   pypi_0    pypi
rich                      13.9.2                   pypi_0    pypi
rpds-py                   0.20.0                   pypi_0    pypi
s3fs                      2023.6.0                 pypi_0    pypi
scanpy                    1.10.3                   pypi_0    pypi
scikit-image              0.24.0                   pypi_0    pypi
scikit-learn              1.5.2                    pypi_0    pypi
scipy                     1.13.1                   pypi_0    pypi
seaborn                   0.13.2                   pypi_0    pypi
session-info              1.0.0                    pypi_0    pypi
setuptools                75.1.0           py39h06a4308_0    defaults
shapely                   2.0.6                    pypi_0    pypi
shellingham               1.5.4                    pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
slicerator                1.1.0                    pypi_0    pypi
snowballstemmer           2.2.0                    pypi_0    pypi
sortedcontainers          2.4.0                    pypi_0    pypi
spatial-image             1.1.0                    pypi_0    pypi
spatialdata               0.2.3                    pypi_0    pypi
spatialdata-io            0.1.5                    pypi_0    pypi
spatialdata-plot          0.2.6                    pypi_0    pypi
sphinx                    7.4.7                    pypi_0    pypi
sphinxcontrib-applehelp   2.0.0                    pypi_0    pypi
sphinxcontrib-devhelp     2.0.0                    pypi_0    pypi
sphinxcontrib-htmlhelp    2.1.0                    pypi_0    pypi
sphinxcontrib-jsmath      1.0.1                    pypi_0    pypi
sphinxcontrib-qthelp      2.0.0                    pypi_0    pypi
sphinxcontrib-serializinghtml 2.0.0                    pypi_0    pypi
sqlite                    3.45.3               h5eee18b_0    defaults
squidpy                   1.6.1                    pypi_0    pypi
stack-data                0.6.3                    pypi_0    pypi
statsmodels               0.14.4                   pypi_0    pypi
stdlib-list               0.11.0                   pypi_0    pypi
superqt                   0.6.7                    pypi_0    pypi
tabulate                  0.9.0                    pypi_0    pypi
tblib                     3.0.0                    pypi_0    pypi
texttable                 1.7.0                    pypi_0    pypi
threadpoolctl             3.5.0                    pypi_0    pypi
tifffile                  2024.8.30                pypi_0    pypi
tinycss2                  1.3.0                    pypi_0    pypi
tk                        8.6.14               h39e8969_0    defaults
tomli                     2.0.2                    pypi_0    pypi
tomli-w                   1.1.0                    pypi_0    pypi
toolz                     1.0.0                    pypi_0    pypi
tornado                   6.4.1                    pypi_0    pypi
tqdm                      4.66.5                   pypi_0    pypi
traitlets                 5.14.3                   pypi_0    pypi
typeguard                 4.3.0                    pypi_0    pypi
typer                     0.12.5                   pypi_0    pypi
typing-extensions         4.12.2                   pypi_0    pypi
tzdata                    2024.2                   pypi_0    pypi
umap-learn                0.5.6                    pypi_0    pypi
urllib3                   1.26.20                  pypi_0    pypi
validators                0.34.0                   pypi_0    pypi
vispy                     0.14.3                   pypi_0    pypi
wcwidth                   0.2.13                   pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.44.0           py39h06a4308_0    defaults
wrapt                     1.16.0                   pypi_0    pypi
xarray                    2024.7.0                 pypi_0    pypi
xarray-dataclasses        1.8.0                    pypi_0    pypi
xarray-datatree           0.0.14                   pypi_0    pypi
xarray-schema             0.0.3                    pypi_0    pypi
xarray-spatial            0.4.0                    pypi_0    pypi
xz                        5.4.6                h5eee18b_1    defaults
yarl                      1.15.3                   pypi_0    pypi
zarr                      2.18.2                   pypi_0    pypi
zict                      3.0.0                    pypi_0    pypi
zipp                      3.20.2                   pypi_0    pypi
zlib                      1.2.13               h5eee18b_1    defaults

Thank you for your help!

@ConstensouxAlexis
Copy link

Hi ! Do you have any update on this issue, or a workaround ? Thank you !

@timtreis
Copy link
Member

timtreis commented Nov 7, 2024

Hey @ConstensouxAlexis, the picture looks correct though, no? Given that your plot background is white, they should show up as white. Or what was the result you expected?

@lisch7
Copy link
Author

lisch7 commented Nov 8, 2024

Hey @ConstensouxAlexis, the picture looks correct though, no? Given that your plot background is white, they should show up as white. Or what was the result you expected?

@timtreis Hi, I expected the background to be transparent so that the underlying HE image would show through, as demonstrated in the tutorial. However, the background is currently solid white.

@degrainger
Copy link

Hi @ConstensouxAlexis @lisch7,

I was running into the same issue as you with the white background. I managed to solve it. I think the set_zero_in_cmap_to_transparent() function is running correctly and 0 values are transparent but it appears white because the image of the tissue is not being displayed. For me this was due to the coordinate_systems argument not being set correctly (was 'global' but for me should have been "downscaled_hires"). I'd recomment inspecting your spatial object and checking that both the image and data you're trying to display together share the same coordinate system.

Hope this helps!
Dave

@LucaMarconato
Copy link
Member

LucaMarconato commented Jan 5, 2025

I would also try passing method='matplotlib' in pl.render_shapes() as datashader may interpret the colormap differently. Please let us know if this is the case; we can ensure the two methods are aligned.

@timtreis
Copy link
Member

timtreis commented Jan 7, 2025

@lisch7, does @degrainger s comment solve your question?

@lisch7
Copy link
Author

lisch7 commented Jan 10, 2025

@lisch7, does @degrainger s comment solve your question?

No. Finally I draw the picture with the white background, not the transparent background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants