Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 215
kurtgn Avatar asked Nov 29 '14 16:11

kurtgn


People also ask

Has no attribute plot?

If matplotlib is successfully installed in your system, but you still have an Attribute Error: module 'matplotlib' has no attribute 'plot'. It means that there is an issue with syntax or we say that there is a syntax error.

Why is %Matplotlib inline?

Why matplotlib inline is used. You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.

What is matplotlib PyLab?

MatPlotLib with Python PyLab is a procedural interface to the Matplotlib object-oriented plotting library. Matplotlib is the whole package; matplotlib. pyplot is a module in Matplotlib; and PyLab is a module that gets installed alongside Matplotlib. PyLab is a convenience module that bulk imports matplotlib.

How do I update python matplotlib?

If you are using the Python version that comes with your Linux distribution, you can install Matplotlib via your package manager, e.g.: Debian / Ubuntu: sudo apt-get install python3-matplotlib. Fedora: sudo dnf install python3-matplotlib. Red Hat: sudo yum install python3-matplotlib.


2 Answers

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.

like image 54
Carsten Avatar answered Oct 04 '22 05:10

Carsten


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') 
like image 24
arno_v Avatar answered Oct 04 '22 04:10

arno_v