Seaborn,对于一些特殊情况,图例中的列表顺序可能与绘图顺序不同。例如,下面的代码:seaborn factorplot:设置图例中显示的系列顺序
df = pds.DataFrame({'group': [-2,-1,0] * 5, 'x' : range(5) * 3, 'y' : range(15)})
sbn.factorplot(kind = 'point', x = 'x', y= 'y', hue = 'group', data = df)
的绘图序列在的基团[-2,-1,0],但图例中的顺序列出[-1,-2,0]。 (前两个交换,可能是由于内部按字符串排序但不是数字)。我当前的解决方法是禁用factorplot中的图例,然后使用matplotlib语法放置图例。只是想知道是否有比我的解决方法更好的方法来做到这一点。
有可能是一个更优雅解决方法,但基本问题是seaborn中的一个已知问题:https://github.com/mwaskom/seaborn/issues/340 – mwaskom 2015-02-12 16:06:03