【问题标题】:Plotnine's scale fill and axis positionPlotnine 的比例填充和轴位置
【发布时间】:2020-06-02 19:09:22
【问题描述】:

我想将 x 轴移动到绘图的顶部并手动填充颜色。但是,ggplot 中的常用方法在 plotnine 中不起作用。当我在scale_x_continuous() 中提供position='top' 时,我收到警告:PlotnineWarning: scale_x_continuous could not recognize parameter 'position'. 我知道位置不在plotnine 的 scale_x_continuous 中,但替换的是什么?此外,scale_fill_manual() 会导致 Invalid RGBA argument: 'color' 错误。具体来说,value 需要一个 array-like 对象。因此,我提供了颜色数组,但仍然有问题。如何手动设置 scale_fill 对象的颜色?

import pandas as pd
from plotnine import *
lst = [[1,1,'a'],[2,2,'a'],[3,3,'a'],[4,4,'b'],[5,5,'b']]
df = pd.DataFrame(lst, columns =['xx', 'yy','lbls']) 

fill_clrs = {'a': 'goldenrod1',
 'b': 'darkslategray3'}
ggplot()+\
  geom_tile(aes(x='xx', y='yy', fill = 'lbls'), df) +\
  geom_text(aes(x='xx', y='yy', label='lbls'),df, color='white')+\
  scale_x_continuous(expand=(0,0), position = "top")+\
   scale_fill_manual(values = np.array(list(fill_clrs.values())))

【问题讨论】:

    标签: python ggplot2 plotnine


    【解决方案1】:

    Plotnine 不支持更改任何轴的位置。

    您可以将颜色值的listdict 传递给scale_fill_manual,前提是它们是可识别的颜色名称。您拥有的颜色模糊不清,无法识别。要查看它是否有效,请尝试使用“红色”和“绿色”,请参阅 https://matplotlib.org/gallery/color/named_colors.html 了解所有命名颜色。否则,您也可以使用十六进制颜色,例如#ff00cc。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      • 2016-08-02
      • 2017-04-15
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多