我正在 jupyter 笔记本中运行 ggplot 代码。我已经安装了plotnine,但是当我尝试运行时,它给我错误AttributeError:'Figure'对象没有属性'set_layout_engine'
代码很简单:
( ggplot(df_nousd)
+ aes(x="raised_currency_code")
+ geom_bar(color="blue", alpha = 0.2)
+ labs(title='Tipo de moneda, capital por startup',
x ='Tipo de moneda',
y = 'Cuantía')
)
出现:
AttributeError Traceback (most recent call last)
\~\\anaconda3\\lib\\site-packages\\IPython\\core\\formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
\--\> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
\~\\anaconda3\\lib\\site-packages\\IPython\\lib\\pretty.py in pretty(self, obj)
392 if cls is not object \
393 and callable(cls.__dict__.get('__repr__')):
\--\> 394 return \_repr_pprint(obj, self, cycle)
395
396 return \_default_pprint(obj, self, cycle)
\~\\anaconda3\\lib\\site-packages\\IPython\\lib\\pretty.py in _repr_pprint(obj, p, cycle)
698 """A pprint that just redirects to the normal repr function."""
699 # Find newlines and replace them with p.break_()
\--\> 700 output = repr(obj)
701 lines = output.splitlines()
702 with p.group():
\~\\anaconda3\\lib\\site-packages\\plotnine\\ggplot.py in __repr__(self)
112 Print/show the plot
113 """
\--\> 114 figure = self.draw(show=True)
115
116 dpi = figure.get_dpi()
\~\\anaconda3\\lib\\site-packages\\plotnine\\ggplot.py in draw(self, show)
239 # Artist object theming
240 self.theme.apply()
\--\> 241 figure.set_layout_engine(PlotnineLayoutEngine(self))
242
243 return self.figure
AttributeError: 'Figure' object has no attribute 'set_layout_engine'
任何人都可以帮助解决这个错误吗?
我在这里搜索一些解决方案,但没有任何地方出现与该报告类似的错误。
Python Control 库也出现了类似的错误,通过更新库很容易解决。
!pip install matplotlib