我有一个数据框(注意-数据是虚拟数据,不代表图中的内容):
Index BGC frequency - Count Proportion of total BGCs both captured and not captured by antiSMASH - %
species_a 1 2
species_b 3 4
... ... ...
我想做一个散点图 BGC frequency - Count
vs Proportion of total BGCs both captured and not captured by antiSMASH - %
,带有根据分类表着色的点 Index
,一个传奇。
import matplotlib.pyplot as plt
from matplotlib import colors
import pandas as pd
colorlist = list(colors.ColorConverter.colors.keys())
captured_df.plot.scatter(x='BGC frequency - Count',
y= 'Proportion of total BGCs both captured and not captured by antiSMASH - %' ,
c = colorlist,
title = 'BGCs with an antiSMASH region')
让我接近:
但我不能得到一个传奇。理想情况下,我希望看到如图所示的第69行:
但当我尝试时:
df.plot.scatter(x='BGC frequency - Count', y='Proportion of total BGCs both captured and not captured by antiSMASH - %', c=df.index, cmap="viridis", s=50)
我得到:
ValueError: 'c' argument must be a mpl color, a sequence of mpl colors or a sequence of numbers, not Index(...list of index species names...)
我不知道这是为什么-我想 cmap
转化为 c
将数据放入正确数据类型的列表中?上面的链接明确地处理分类数据-
如果将一个分类列传递给c,则将生成一个离散的颜色条
另外请注意,我不想要数字颜色条-这没有多大用处:
感谢阅读:d
暂无答案!
目前还没有任何答案,快来回答吧!