DingWB / PyComplexHeatmap

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

How to set vmax and vmin of cmap in ClusterMapPlotter() #75

Closed XuejianXiong closed 6 months ago

XuejianXiong commented 6 months ago

Good morning,

I would like to set a same range, i.e. vmin and vmax, of cmap in the heatmap for several figures using the function ClusterMapPlotter(). My code is as follows:

heatmap = pch.ClusterMapPlotter( data=heatmap_data.T, top_annotation=col_ha, col_cluster=False, row_cluster=True, label="values", col_dendrogram=False, row_dendrogram=True, show_rownames=True, show_colnames=False, legend_gap=7, vmin=0, vmax=30, cmap="parula", rasterized=True, tree_kws={"row_cmap": "Dark2"}, ylabel=f"Protein (10 in total)", xlabel=f"Run (100 in total)", legend_hpad=7, yticklabels=True, xticklabels_kws={"labelrotation": -45, "labelcolor": "blue"}, yticklabels_kws={"labelsize": 8}, )

However, the legend in the output figure did not show the range from 0 to 30, but the real minimum and maximum in the heatmap_data.

I would like to know how to solve this problem. Thank you!

DingWB commented 6 months ago

Were you using the latest version of PyComplexHeatmap? If not, please upgrade to the latest version. @XuejianXiong

XuejianXiong commented 6 months ago

Thank you @DingWB. I upgraded to the version 1.7.3, but still have the same problem.

DingWB commented 6 months ago

This is weird; this bug was fixed a long time ago. Please print print(heatmap.kwargs['vmax'],heatmap.kwargs['vmin'],heatmap.legend_kws) after running heatmap = pch.ClusterMapPlotter(**) and show me the output. @XuejianXiong

XuejianXiong commented 6 months ago

The output looks good "30 0 {'vmin': 0, 'vmax': 30}". However in the figures (attached), it still shows different values in the legend for different heatmaps.

Screenshot 2024-05-15 at 5 30 12 PM

@DingWB

DingWB commented 6 months ago

Please install the latest version from github, and follow this example to see whether the legend has the same vmax and vmin as provided in the code (vmin=-2.2,vmax=2.3,).

If it is still not working, then you need to paste your data and code here.

DingWB commented 6 months ago

Hi @XuejianXiong ,

How is it going? Did it work?

XuejianXiong commented 6 months ago

Hi @DingWB,

It worked! It seems my virtual environment caused issues with the package upgrading. I have to manually delete the old version and reinstall using pip. Thank you for your help!

Best, Xuenjian