1

Code

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)

ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

ax.set_ylim(-2,2)
plt.show()

from http://matplotlib.org/1.2.0/users/annotations_intro.html
return

TypeError: 'dict' object is not callable

I manged to fixed it with

xxx={'facecolor':'black', 'shrink':0.05}
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
            arrowprops=xxx,
            )

Is this the best way ?
Also what caused this problem ? ( I know that this started with Python 2.7)

So if somebody know more, please share.

2
  • 1
    The code you posted works ok for me (using ipython with python v2.7.3). Perhaps you have a variable named "dict", which prevents the built-in behaviour of dict? Commented Jul 11, 2013 at 9:28
  • You are correct. I am testing some examples with ipython notebook, so dict was used previously. I had to do del dict, to make it work. You can write this as answer. Commented Jul 11, 2013 at 10:54

1 Answer 1

1

Since the code looks fine and runs ok on my machine, it seems that you may have a variable named "dict" (see this answer for reference). A couple of ideas on how to check:

  • use Pylint.
  • if you suspect one specific builtin, try checking it's type (type(dict)), or look at the properties/functions it has (dir(dict)).
  • open a fresh notebook and try again, if you only observe the problem in interactive session.
  • try alternate syntax to initialise the dictionary

    ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
        arrowprops={'facecolor':'black', 'shrink':0.05})
    
  • try explicitly instancing a variable of this type, using the alternate syntax (as you did already).

Sign up to request clarification or add additional context in comments.

Comments

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.