DingWB / PyComplexHeatmap

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

'DataFrame' object has no attribute 'C' #82

Open medmaca opened 1 month ago

medmaca commented 1 month ago

I'm working my way through the examples, and when I get to the dotHeatmap example Add parameter hue and use different cmap and marker for different groups:

plt.figure(figsize=(8,8))
cm = DotClustermapPlotter(corr_mat,x='level_0',y='level_1',value='correlation',hue='Level',
              cmap={'High':'Reds','Middle':'Purples','Low':'Greens'},
              colors={'High':'red','Middle':'purple','Low':'green'},
              marker={'High':'P','Middle':'*','Low':'D'},spines=True,
              vmax=1,vmin=0)
plt.show()

I get the following output:

/root/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/dotHeatmap.py:362: FutureWarning: The provided callable <function mean at 0x7f1dc05ab880> is currently using DataFrameGroupBy.mean. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string "mean" instead.
  data2d = data.pivot_table(
Starting plotting..
Starting calculating row orders..
Reordering rows..
Starting calculating col orders..
Reordering cols..
Plotting matrix..
Inferred max_s (max size of scatter point) is: 132.808800071564

And the following error:

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_13878/1321454167.py in ?()
      1 plt.figure(figsize=(8,8))
----> 2 cm = pch.DotClustermapPlotter(corr_mat,x='level_0',y='level_1',value='correlation',hue='Level',
      3               cmap={'High':'Reds','Middle':'Purples','Low':'Greens'},
      4               colors={'High':'red','Middle':'purple','Low':'green'},
      5               marker={'High':'P','Middle':'*','Low':'D'},spines=True,

~/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/dotHeatmap.py in ?(self, data, x, y, value, hue, s, c, marker, alpha, color_legend_kws, cmap_legend_kws, dot_legend_kws, dot_legend_marker, aggfunc, value_na, hue_na, s_na, c_na, x_order, y_order, spines, grid, max_s, **kwargs)
    354                 self.dot_legend_kws = dot_legend_kws
    355                 self.dot_legend_marker=dot_legend_marker
    356                 self.max_s=max_s
    357 
--> 358                 super().__init__(**kwargs)

~/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/clustermap.py in ?(self, data, z_score, standard_scale, top_annotation, bottom_annotation, left_annotation, right_annotation, row_cluster, col_cluster, row_cluster_method, row_cluster_metric, col_cluster_method, col_cluster_metric, show_rownames, show_colnames, row_names_side, col_names_side, xticklabels_kws, yticklabels_kws, row_dendrogram, col_dendrogram, row_dendrogram_size, col_dendrogram_size, row_split, col_split, row_dendrogram_kws, col_dendrogram_kws, tree_kws, row_split_order, col_split_order, row_split_gap, col_split_gap, mask, subplot_gap, legend, legend_kws, plot, plot_legend, legend_anchor, legend_gap, legend_width, legend_hpad, legend_vpad, legend_side, cmap, label, xlabel, ylabel, xlabel_kws, ylabel_kws, xlabel_side, ylabel_side, xlabel_bbox_kws, ylabel_bbox_kws, rasterized, legend_delta_x, verbose, **kwargs)
   1282                 self.ylabel_side = ylabel_side
   1283                 self.xlabel_bbox_kws = xlabel_bbox_kws
   1284                 self.ylabel_bbox_kws = ylabel_bbox_kws
   1285                 if plot:
-> 1286                         self.plot()
   1287                         if plot_legend:
   1288                                 if legend_anchor == "auto":
   1289                     if (

~/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/clustermap.py in ?(self, ax, subplot_spec, row_order, col_order)
   2296                         if self.verbose >= 1:
   2297                                 print("Starting calculating col orders..")
   2298                         self._reorder_cols()
   2299                         col_order = self.col_order
-> 2300                 self.plot_matrix(row_order=row_order, col_order=col_order)
   2301                 if not self.top_annotation is None:
   2302                         gs = self.gs[0, 1] if not self.col_dendrogram else self.top_gs[1, 0]
   2303                         self.top_annotation._set_orentation("up")

~/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/dotHeatmap.py in ?(self, row_order, col_order)
    522                                 # ax1.set_xlim([0, len(rows)])
    523                                 # ax1.set_ylim([0, len(cols)])
    524                                 kwargs = self.kwargs.copy()
    525                                 # print(kwargs)
--> 526                 dotHeatmap2d(
    527                                         self.data2d.loc[rows, cols],
    528                                         cmap=kwargs.pop("cmap", self.cmap),
    529                                         ax=ax1,

~/miniforge3/lib/python3.10/site-packages/PyComplexHeatmap/dotHeatmap.py in ?(***failed resolving arguments***)
    205                 ax.scatter(
    206                                         x=df2.X.values,
    207                                         y=df2.Y.values,
    208                                         s=df2.S * max_s,
--> 209                                         c=df2.C.values,
    210                                         **kwargs
    211                 )  #
    212         else:

~/miniforge3/lib/python3.10/site-packages/pandas/core/generic.py in ?(self, name)
   6295             and name not in self._accessors
   6296             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   6297         ):
   6298             return self[name]
-> 6299         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'C'

Desktop:

Python versions installed:

DingWB commented 1 month ago

Hi @medmaca , Sorry for this bug. I have already fixed this bug, could you please uninstall and reinstall from GitHub and test it again? pip uninstall -y PyComplexHeatmap && pip install git+https://github.com/DingWB/PyComplexHeatmap Please let me know whether it works or not; I will release a new version if there is no problem.

DingWB commented 1 month ago

I have already released a new version (1.7.6). Please let me know whether there is any issue with this release. @medmaca

medmaca commented 1 month ago

Hi, thank you so much for such a quick reply and fix. I've now downloaded the latest version and it fixes that example code.

However, I am slightly confused by the merit of that example.

The website example (altered for colour blind, i.e. me): `plt.figure(figsize=(8,8)) cm = pch.DotClustermapPlotter(corr_mat,x='level_0',y='level_1',value='correlation',hue='Level',

cmap={'High':'Reds','Middle':'Purples','Low':'Greens'},

        #   colors={'High':'red','Middle':'purple','Low':'green'},
          cmap={'High':'Reds','Middle':'Oranges','Low':'Blues'},
          colors={'High':'red','Middle':'orange','Low':'blue'},
          marker={'High':'P','Middle':'*','Low':'D'},spines=True,
          vmax=1,vmin=0)

plt.show()` image

My altered version of the same example: `plt.figure(figsize=(8,8)) cm = pch.DotClustermapPlotter(corr_mat,x='level_0',y='level_1',value='correlation',hue='Level', s='correlation',c='correlation', cmap={'High':'Reds','Middle':'Oranges','Low':'Blues'}, colors={'High':'red','Middle':'orange','Low':'blue'}, marker={'High':'P','Middle':'*','Low':'D'},spines=True, vmax=1,vmin=-1, grid=None)

plt.show()`

image

The example on the website I find really confusing as the largest diamonds are really the lowest correlations, this makes it really hard to interpret the plot. Am I missing something obvious?

Thanks again for all the hard work you've put into this marvelous package.

DingWB commented 1 month ago

Sorry for the inconvenience. I have been trying to make it simpler, but you know, there are too many parameters. Please let me know if you have any better ideas.