简体   繁体   English

ggplot Python:错误:TypeError:“模块”对象不可调用

[英]ggplot Python : Error : TypeError: 'module' object is not callable

Hi I am trying to use ggplot library in Python.嗨,我正在尝试在 Python 中使用 ggplot 库。 So I pip install gglot in my Anaconda command prompt.所以我在我的 Anaconda 命令提示符下 pip install gglot 。 I tried basic plotting (Example from http://ggplot.yhathq.com/docs/geom_density.html ) in jupyter notebook.我在 jupyter notebook 中尝试了基本绘图(来自http://ggplot.yhathq.com/docs/geom_density.html 的示例)。 But I am getting error saying 'TypeError: 'module' object is not callable'.但是我收到错误消息,说“TypeError: 'module' object is not callable”。 There is no error while running the import statement of ggplot in the noteobok.在noteobok中运行ggplot的import语句没有报错。 But I am getting error while running the ggplot() + geom statement.但是在运行 ggplot() + geom 语句时出现错误。

from ggplot import *
df = pd.DataFrame({
    "x": np.random.normal(0, 10, 1000),
    "y": np.random.normal(0, 10, 1000),
    "z": np.random.normal(0, 10, 1000)
})
df = pd.melt(df)

ggplot(aes(x='value', color='variable'), data=df) + \
    geom_density()

TypeError Traceback (most recent call last)
<ipython-input-12-162182859f18> in <module>()
      6 df = pd.melt(df)
      7 
----> 8 ggplot(aes(x='value', color='variable'), data=df) +     geom_density()

TypeError: 'module' object is not callable

Is there something I am missing here ?有什么我在这里想念的吗?

Looks like ggplot is a module rather than a class.看起来ggplot是一个模块而不是一个类。 You should either do ggplot.ggplot(<snip>) or change your import to from ggplot import ggplot .您应该执行ggplot.ggplot(<snip>)或将导入更改为from ggplot import ggplot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM