BMichell
BMichell

Reputation: 3751

AttributeError when setting matplotlib style

I have a python script which uses the following import list:

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

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

It then imports a textfile into a dataframe, creates some additional columns in the df and creates two plots.

I need to be able to call it from Matlab (for a number of tedious reasons...) and I did this by typing the following at the Matlab prompt:

dos('myfile.py')

Which threw the following error:

Traceback (most recent call last): 
  File "D:\Documents\Python Scripts\XXXXXXXXX.py", line 8, in     <module> 
    matplotlib.style.use('ggplot') 
AttributeError: 'module' object has no attribute 'style' 

However if I comment the line asking for the ggplot style, it runs fine and generates the plots correctly in standard matplotlib formatting.

Any suggestions as to why this might be the case?

Best Regards,

Ben

Upvotes: 3

Views: 3787

Answers (1)

ODiogoSilva
ODiogoSilva

Reputation: 2414

style is an attribute of pyplot, not matplotlib

try:

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

Upvotes: 14

Related Questions