我有一个数据框(nb - 数据是虚拟数据,不代表图中的内容):
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 - %
,其中的点根据 categoricalIndex
和一个图例着色。
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