DingWB / PyComplexHeatmap

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

`HeatmapAnnotation` related issue – empty labeling #31

Closed abearab closed 1 year ago

abearab commented 1 year ago

I have trouble using HeatmapAnnotation. I keep getting empty annotation... any thought?

    PathwayModule = [
        'WPM' if node in list(set(sub_mat.columns) & set(gmt[geneset_name])) else 'BPM' 
        for node in sub_mat.columns
    ]

    fig, ax = plt.subplots(figsize=(2 * rel,1.6 * rel))

    col_colors_dict={
        'WPM':'#1E93AE',
        'BPM':'#FF9C00'
    }    
    col_ha = ch.HeatmapAnnotation(
        label=ch.anno_label(
            pd.Series(PathwayModule),merge=True,rotation=90,extend=True,
            adjust_color=True,luminance=0.75,
            colors=col_colors_dict,
            relpos=(0.5,0)
        ),
        PathwayModule=ch.anno_simple(
            pd.Series(PathwayModule),
            colors=col_colors_dict,
        ), axis=1,
        label_side='right',
        verbose=0,
        # plot=False,
        legend=False
    )
    plot_cm = ch.ClusterMapPlotter(
        sub_mat,
        legend_gap=5,legend_width=5,legend_hpad=2,legend_vpad=5,
        right_annotation=col_ha,
        col_dendrogram=True,
        row_dendrogram=True,
        vmin=-1, vmax=1,
        cmap = 'BlueYellow',
        verbose=False,
        legend=False,
        # plot=False,
        # show_rownames=True,show_colnames=True
    )

image

DingWB commented 1 year ago

I guess it is the issue of ax; you created ax yourself but didn't pass it to the ClusterMapPlotter .plot. You can remove fig, ax = plt.subplots(figsize=(2 * rel,1.6 * rel)) and try:

plt.figure(figsize=(2 * rel,1.6 * rel))
plot_cm = ch.ClusterMapPlotter(
        sub_mat,
        legend_gap=5,legend_width=5,legend_hpad=2,legend_vpad=5,
        right_annotation=col_ha,
        col_dendrogram=True,
        row_dendrogram=True,
        vmin=-1, vmax=1,
        cmap = 'BlueYellow',
        verbose=False,
        legend=False,
        # plot=False,
        # show_rownames=True,show_colnames=True
    )
plt.savefig(...)
plt.show()
DingWB commented 1 year ago

There are many examples on the documentation website, you can follow an example and re-organize your code.

Please let me know if you still have this kind of issue.

abearab commented 1 year ago

Sorry for late response. My issue was due to pd.Series index issue. That should be matched with the actual heatmap data. Thanks