我写这个脚本是为了从附加的数据帧创建一个彩色映射的图。
这是代码
biaxial_plot_ICOS_PD1 = sorted_df.plot.scatter(x="ICOS - costimulator:Cyc_14_ch_4"
, y="PD-1 - checkpoint:Cyc_12_ch_4"
, c="ClusterName", colormap='viridis', s=50)但我知道这个错误
ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['CD4+ T cells' 'CD4+ T cells' 'CD4+ T cells' ... 'CD4+ T cells CD45RO+' 'CD4+ T cells CD45RO+' 'CD4+ T cells GATA3+']sorted_df:

发布于 2022-06-26 13:14:52
当您向c参数提供列标签时,该列的值应该是有效的数字,根据所提供的颜色映射到颜色。来自docs of DataFrame.plot.scatter
c : str、int或类似数组的可选
每个点的颜色。可能的价值是:
对标记点进行着色。
c参数不直接解释为“本列的颜色”。如果您想要这样的东西,请使用seaborn。
在您的示例中,您似乎希望基于ClusterName对其进行着色,因此可以使用groupby + ngroup,以便将每个ClusterName映射到一个不同的整数,即不同的颜色。
这应该能行
cluster_colors = sorted_df.groupby('ClusterName').ngroup()
biaxial_plot_ICOS_PD1 = sorted_df.plot.scatter(x="ICOS - costimulator:Cyc_14_ch_4",
y="PD-1 - checkpoint:Cyc_12_ch_4",
c=cluster_colors, colormap='viridis', s=50)https://stackoverflow.com/questions/72761758
复制相似问题