kurtgn
kurtgn

Reputation: 8710

matplotlib.pyplot has no attribute 'style'

I am trying to set a style in matplotlib as per tutorial http://matplotlib.org/users/style_sheets.html

import matplotlib.pyplot as plt
plt.style.use('ggplot')

but what I get in return is:

AttributeError: 'module' object has no attribute 'style'

My matplotlib version is 1.1.1 (and I'm on a Mac running Mavericks). Where are the styles in this version?

thanks!

Upvotes: 32

Views: 30031

Answers (5)

Wyatt_Earp
Wyatt_Earp

Reputation: 87

For MatPlotLib version 3.6.3 and above, the following code to be used to use "seaborn" style as the seaborn has been deprecated since version 3.6:

import matplotlib
matplotlib.use
import matplotlib.pyplot as plt
plt.style.use("seaborn-v0_8")

Upvotes: 1

wander95
wander95

Reputation: 1366

For people using matplotlib 2.x and discovering this question can use the following snippet:

import matplotlib.style
import matplotlib as mpl
mpl.style.use('classic')   # any style.

This is described in the documentation here. Note the import matplotlib.style is important.

Upvotes: 11

Hiten
Hiten

Reputation: 71

I tried all solutions listed on StackOverflow but somehow none of these work for me. Finally I found a method which worked. Following are the details: Environment: OS : Ubuntu 16 Python Version : 3.5. MatPlotLib Version : 2.0.2

Correct Way of importing 'style module'

import matplotlib
matplotlib.use
import matplotlib.pyplot as plt
plt.style.use('ggplot')

The matplotlib help reads:

:func:~matplotlib.use (ignore syntax as "`" did not work either on command line or script file) a function for setting the matplotlib backend. If used, this function must be called immediately after importing matplotlib for the first time. In particular, it must be called before importing pylab (if pylab is imported).

Somehow without issuing this command, it was not possible to access the 'Style' module.

Hope this helps.

Upvotes: 7

arno_v
arno_v

Reputation: 20257

In ipython notebook I also had to include %matplotlib inline, otherwise I would still get the same error.

%matplotlib inline
import matplotlib
matplotlib.style.use('ggplot')

Upvotes: 24

Carsten
Carsten

Reputation: 18446

My matplotlib version is 1.1.1

There's your problem. The style package was added in version 1.4. You should update your version.

Upvotes: 22

Related Questions