Reputation: 1033
I'm attempting to run the following code in Spyder (which uses an IPython console):
import numpy as np
import matplotlib as plt
labels = ['python\nloop', 'numpy\nbroadc.', 'sklearn', 'fortran/\nf2py', 'scipy', 'cython', 'numba']
timings = [13.4, 0.111, 0.0356, 0.0167, 0.0129, 0.00987, 0.00912]
x = np.arange(len(labels))
ax = plt.axes(xticks=x, yscale='log')
ax.bar(x - 0.3, timings, width=0.6, alpha=0.4, bottom=1E-6)
ax.grid()
ax.set_xlim(-0.5, len(labels) - 0.5)
ax.set_ylim(1E-3, 1E2)
ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda i, loc: labels[int(i)]))
ax.set_ylabel('time (s)')
ax.set_title("Pairwise Distance Timings")
However, I get the following error:
Traceback (most recent call last):
File "<ipython-input-1-46193480d26c>", line 1, in <module>
runfile('C:/Users/owner/.spyder-py3/temp.py', wdir='C:/Users/owner/.spyder-py3')
File "C:\Users\owner\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\owner\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/owner/.spyder-py3/temp.py", line 9, in <module>
ax = plt.axes(xticks=x, yscale='log')
TypeError: 'module' object is not callable
Am I missing something? As far as I know, this code works fine in IDLE, however I could not install NumPy with PIP so I took an easy route and installed Anaconda.
Upvotes: 1
Views: 75
Reputation: 751
You seem to use the pyplot module of matplotlib (that's what plt
usually stands for). It should be imported like:
import matplotlib.pyplot as plt
If I change that line, your code works wonderfully for me :)
Upvotes: 1