1

While trying to set the "styles" module in matplotlib I get an AttributeError as below:

import matplotlib.pyplot as plt
plt.styles.use("ggplot")

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    plt.styles.use("ggplot")
AttributeError: 'module' object has no attribute 'styles'

Why is that? How can I fix it? I am using python 3 64 bit

EDIT: I get the same error using

plt.style.use("ggplot")

1 Answer 1

2

The sub-package is style, not styles. The documentation can be found here. So use

import matplotlib.pyplot as plt
plt.style.use('ggplot')
Sign up to request clarification or add additional context in comments.

4 Comments

I get this error even in the shell typing it in as the second line after the import statement. If I had used it in a script the script I would put it at the top after the import, and the program won't run past it.
I am using python 3.3 64 bit, and matplotlib 1.2.0. The error is an AttributeError identical to the one in the body of the question above.
That's quite an old version of matplotlib. The latest version is 1.4.2. You may want to try updating to see if this fixes your issue, as I'm using 1.4.2 and can do plt.style.use('ggplot') fine.
Ok, let me try this solution, thanks. I'll let you know soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.