DingWB / PyComplexHeatmap

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

pandas inssure when ploting #83

Closed Simmon23 closed 4 weeks ago

Simmon23 commented 1 month ago

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)


ValueError Traceback (most recent call last)

in 4 cmap='Blues', label='Expression', 5 legend=True,legend_anchor='auto', ----> 6 yticklabels_kws=dict(labelcolor='black',labelsize=15),legend_gap=5) 7 plt.show() ~/.local/lib/python3.7/site-packages/PyComplexHeatmap/clustermap.py in __init__(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) 1284 self.ylabel_bbox_kws = ylabel_bbox_kws 1285 if plot: -> 1286 self.plot() 1287 if plot_legend: 1288 if legend_anchor == "auto": ~/.local/lib/python3.7/site-packages/PyComplexHeatmap/clustermap.py in plot(self, ax, subplot_spec, row_order, col_order) 2306 subplot_spec=gs, 2307 idxs=col_order, -> 2308 wspace=self.wspace, 2309 ) 2310 if not self.bottom_annotation is None: ~/.local/lib/python3.7/site-packages/PyComplexHeatmap/annotations.py in plot_annotations(self, ax, subplot_spec, idxs, wspace, hspace) 1930 else: 1931 ax1.set_ylim([0, len(idx)]) -> 1932 ann.plot(ax=ax1, axis=self.axis) #subplot_spec=gs 1933 if self.axis == 1: 1934 # ax1.yaxis.set_visible(False) ~/.local/lib/python3.7/site-packages/PyComplexHeatmap/annotations.py in plot(self, ax, axis) 361 xticklabels=False, 362 yticklabels=False, --> 363 **self.plot_kws 364 ) #y will be inverted inside plot_heatmap 365 ax.tick_params( ~/.local/lib/python3.7/site-packages/PyComplexHeatmap/clustermap.py in plot_heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, xticklabels, yticklabels, mask, na_col, ax, linewidths, linecolor, **kwargs) 570 plot_data = data.values 571 else: --> 572 plot_data = np.asarray(data) 573 data = pd.DataFrame(plot_data) 574 # Validate the mask and convert to DataFrame /cluster/apps/anaconda3/2020.02/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order) 83 84 """ ---> 85 return array(a, dtype, copy=False, order=order) 86 87 ~/.local/lib/python3.7/site-packages/pandas/core/arrays/categorical.py in __array__(self, dtype) 1449 categorical.categories.dtype. 1450 """ -> 1451 ret = take_nd(self.categories._values, self._codes) 1452 if dtype and not is_dtype_equal(dtype, self.categories.dtype): 1453 return np.asarray(ret, dtype) ~/.local/lib/python3.7/site-packages/pandas/core/array_algos/take.py in take_nd(arr, indexer, axis, fill_value, allow_fill) 106 107 arr = np.asarray(arr) --> 108 return _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill) 109 110 ~/.local/lib/python3.7/site-packages/pandas/core/array_algos/take.py in _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill) 152 arr.ndim, arr.dtype, out.dtype, axis=axis, mask_info=mask_info 153 ) --> 154 func(arr, indexer, out, fill_value) 155 156 if flip_order: pandas/_libs/algos_take_helper.pxi in pandas._libs.algos.take_1d_int64_int64() ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
DingWB commented 1 month ago

How do I reproduce this error? If you run the example code from the docu website, did you get a similar error? @Simmon23

Simmon23 commented 1 month ago

If I restart the kernal when this error appeared and re-running plotting it can be solved sometiomes.

Simmon23 commented 4 weeks ago

I use the same data, but sometimes it appeared error above

Simmon23 commented 4 weeks ago

which pandas version did you use when testing pycomplexheatmap?

Simmon23 commented 4 weeks ago

And sometimes cmap = 'auto' went well but sometimes it remind me can not assign cmap for XXX. They are the same data

DingWB commented 4 weeks ago

Here is the version of the independencies: https://github.com/DingWB/PyComplexHeatmap/blob/b875d8c4818f7a0fc9a7484e841009cb36d10efa/pyproject.toml#L12

I guess it is related to the version of matplotlib

Simmon23 commented 4 weeks ago

My packages meets the above criteria

DingWB commented 4 weeks ago

Could you please try a different version of pandas or matplotlib?

Simmon23 commented 4 weeks ago

This error was solved by tran df_cols type as 'O'