如何在 Python 中使用 scale_color_manual?

Aye*_*own 3 python r data-visualization ggplot2 plotnine

我已经使用 ggplot 很长时间了,并且在 R 中使用它非常舒服。我现在正在学校使用 Python,我最难理解这个错误。当我尝试使用 scale_color_manual 将颜色手动分配给名为“CellTypeOther”的具有唯一值 0/1 的变量时,我不断收到以下错误:

NameError: name 'c' is not defined
Run Code Online (Sandbox Code Playgroud)

这是我创建 ggplot 的代码:

from plotnine import * 
plot = (
  ggplot(Y_tsne,aes(x = 'X',y = 'Y'))
   + geom_point(aes(color = 'CellTypeOther'),alpha = 0.4,size = 2)
   + scale_color_manual(c("blue","red"))
)
Run Code Online (Sandbox Code Playgroud)

没有最后一行,情节渲染得很好。有没有人对可能发生的事情有任何线索?我不能分享我的数据,因为它很敏感。

重要说明:我正在使用 plotnine Python 模块来利用 ggplot2。

mt1*_*022 5

你应该使用[]而不是c()在 python 中:

在此处输入图片说明