Simple matplotlib Annotating example not working in Python 2.7 -


code

import numpy np import matplotlib.pyplot 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 not callable

i manged fixed with

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

is best way ?
caused problem ? ( know started python 2.7)

so if know more, please share.

since code looks fine , runs ok on machine, seems may have variable named "dict" (see this answer reference). couple of ideas on how check:

  • use pylint.
  • if suspect 1 specific builtin, try checking it's type (type(dict)), or @ properties/functions has (dir(dict)).
  • open fresh notebook , try again, if observe problem in interactive session.
  • try alternate syntax initialise dictionary

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


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -