You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot be shown in transparent colors when Plotting the gene expression data #554
When I reproduce according to the code of the official tutorial Technology focus: Visium HD in jupyterlab, I get an incorrect figure: transparent colors RGBA(1.0,1.0,1.0,0.0) is replaced by white RGB(1.0,1.0,1.0).
How to modify the code?
importmatplotlib.cmascmimportmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlib.colorsimportLinearSegmentedColormap# modify the viridis colormap, so that the top color is a green (better visible on the H&E pink), and such that# the value 0 leads to a transparent colorviridis=cm.get_cmap("viridis", 256)
# using 0.8 instead of 1.0 truncates the colormapcolors=viridis(np.linspace(0, 0.8, 256))
# set the color of zero to be transparentcolors[0, :] = [1.0, 1.0, 1.0, 0.0]
new_cmap=LinearSegmentedColormap.from_list("truncated_viridis", colors)
/tmp/ipykernel_2057419/2380312474.py:8:MatplotlibDeprecationWarning:The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use ''matplotlib.colormaps[name]'' or ''matplotlib.colormaps.get_cmap(obj)'' instead.
viridis= cm.get cmap("viridis",256)
clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]for integers)
clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255]for integers)
To make it easier for others to reproduce this issue, I've simplified the code. (circle not square )
importspatialdataassdvisium_hd_zarr_path="/Path/to/visium_hd_Mu_intestin/data.zarr"# input datasdata=sd.read_zarr(visium_hd_zarr_path)
sdata# make the var names uniquefortableinsdata.tables.values():
table.var_names_make_unique()
importmatplotlibasmpl#import matplotlib.cm as cmimportmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlib.colorsimportLinearSegmentedColormap# modify the viridis colormap, so that the top color is a green (better visible on the H&E pink), and such that# the value 0 leads to a transparent colorviridis=mpl.colormaps.get_cmap("viridis")
# using 0.8 instead of 1.0 truncates the colormapcolors=viridis(np.linspace(0, 0.8, 256))
# set the color of zero to be transparentcolors[0, :] = [1.0, 1.0, 1.0, 0.0]
new_cmap=LinearSegmentedColormap.from_list("truncated_viridis", colors)
plt.get_cmap(new_cmap)
gene_name="AA986860"forbin_sizein [16, 8, 2]:
sdata_small.pl.render_images("Visium_HD_Mouse_Small_Intestine_full_image").pl.render_shapes(
f"Visium_HD_Mouse_Small_Intestine_square_{bin_size:03}um", color=gene_name, cmap=new_cmap
).pl.show(coordinate_systems="global", title=f"bin_size={bin_size}µm", figsize=(10, 10))
The output is likely.
I thought of two possible reasons: 1) The matplotlib section sets the color bar code incorrectly; 2) Errors in gene expression value conversion.
Activity
Bioin-Mixologist commentedon Apr 30, 2024
The data from:
wget -c https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_hd_3.0.0_io.zip &To make it easier for others to reproduce this issue, I've simplified the code. (circle not square )
The output is likely.
I thought of two possible reasons: 1) The matplotlib section sets the color bar code incorrectly; 2) Errors in gene expression value conversion.
Bioin-Mixologist commentedon May 2, 2024
The author has already answered in spatialdata-plot issues 242 and release spatialdata-plot 0.2.2, spatialdata-plot pull 239.
The transparent code1.0 from spatialdata-plot issues 242.
after upgrade spatialdata-plot 0.2.2, the figure is ok!
the get_cmap() question is new issue spatialdata-plot issues 255
Bioin-Mixologist commentedon May 2, 2024
Yeh