pythonpython-2.7python-ggplot

ggplot Python : Error : TypeError: 'module' object is not callable


Hi I am trying to use ggplot library in Python. So I pip install gglot in my Anaconda command prompt. I tried basic plotting (Example from http://ggplot.yhathq.com/docs/geom_density.html) in jupyter notebook. But I am getting error saying 'TypeError: 'module' object is not callable'. There is no error while running the import statement of ggplot in the noteobok. But I am getting error while running the ggplot() + geom statement.

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 ?


Solution

  • Looks like ggplot is a module rather than a class. You should either do ggplot.ggplot(<snip>) or change your import to from ggplot import ggplot.