DingWB / PyComplexHeatmap

PyComplexHeatmap: A Python package to plot complex heatmap (clustermap)
https://dingwb.github.io/PyComplexHeatmap/
MIT License
249 stars 28 forks source link

anno_scatterplot with custom cmap/colors #34

Closed Laolga closed 1 year ago

Laolga commented 1 year ago

Hi! Is it possible to make the scatterplot with custom colors? I tried to give my color list as colors, but that argument accepts only single color, tried providing my color list as ListedColormap(list_of_colors), but cmap accepts only strings as an argument. Is there any way?

DingWB commented 1 year ago

Thanks for your question; you can try to register your custom cmap using the following:

c = LinearSegmentedColormap.from_list('my_cmap', [(0, 'blue'), (0.5, 'yellow'), (1, 'red')])
plt.register_cmap(cmap=c)
# After registering, my_cmap is the name of your custom cmap
# then you can use cmap='my_cmap' as the parameter in anno_scatterplot

Or similar to ListedColormap

c = ListedColormap(
            colors,
            'my_cmap')
plt.register_cmap(cmap=c)

I hI hope this answer helps.