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
modify colormap so that 0 values have alpha=0 #242
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)
it's actually really nice and result to this
I think it could just be an option to do this modification internally? with an argument like alpha_value_zero: bool = True or so, wdyt?
Could also be a helper function that takes an arbitrary cmap and returns a modified one? Personally, I'm not a big fan of the plotting functions accumulating too many arguments.
I've been using something similar for visium data actually... this version makes a gradient from transparent to viridis:
I do see the usecase but I'm not a fan of putting 0 as "missing", in this case I think it'd be cleaner to set those to NA and hide them through na_color. A hacky way would be to instead expose an option that modifies a given cmap so that the gradient towards 0 is not just towards white but transparent white?
@timtreis is there a new recommended way to the achieve the transparent effect for zero values or shall we keep using the old code (i.e. manually modifying the cmap)?
I'm not a big fan of the plotting functions accumulating too many arguments.
I'd really agree with Gregor here. This feels like a very specific thing that I don't necessarily think should be part of the function signature. I'd be in favor of casually showing such a function in one of the tutorials so that we can link to it, though? wdyt?
Activity
grst commentedon Apr 9, 2024
Could also be a helper function that takes an arbitrary
cmapand returns a modified one? Personally, I'm not a big fan of the plotting functions accumulating too many arguments.I've been using something similar for visium data actually... this version makes a gradient from transparent to viridis:
timtreis commentedon Apr 11, 2024
I do see the usecase but I'm not a fan of putting 0 as "missing", in this case I think it'd be cleaner to set those to
NAand hide them throughna_color. A hacky way would be to instead expose an option that modifies a given cmap so that the gradient towards 0 is not just towards white but transparent white?Bioin-Mixologist commentedon May 2, 2024
hello, @giovp @timtreis . I used the same code according to the tutorial, but the result is not ideal, is it the version reason?

I have open one issue Cannot be shown in transparent colors when Plotting the gene expression data #554 at spatialdata.
There are also people who have recently had the same problem as me.
Thanks!
LucaMarconato commentedon May 2, 2024
Thanks for reporting, I will answer with the solution in the linked issue.
Bioin-Mixologist commentedon May 2, 2024
Thankfully @LucaMarconato @timtreis @grst , after the update spatialdata-plot, the issue has been resolved and the issue Cannot be shown in transparent colors when Plotting the gene expression data #554 will be closed, but there may be new questions about this code, and a new issue #255 has been open.
LucaMarconato commentedon Jul 11, 2024
@timtreis is there a new recommended way to the achieve the transparent effect for zero values or shall we keep using the old code (i.e. manually modifying the cmap)?
timtreis commentedon Jul 11, 2024
I'd really agree with Gregor here. This feels like a very specific thing that I don't necessarily think should be part of the function signature. I'd be in favor of casually showing such a function in one of the tutorials so that we can link to it, though? wdyt?
giovp commentedon Jul 12, 2024
maybe in a utils function then? otherwise the code to do it gets lost in github issues
LucaMarconato commentedon Jul 12, 2024
yeah maybe a tiny utils would be helpful