An error when running an example
Question: I am trying to use the `numpy.fft.fft`.

When I run the example in the bottom of this page
([numpy.fft.fft](http://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.fft.html#numpy.fft.fft)),
there is an error and the figure is weird.

How to make it right? I guess the error is related with `backend_macosx.py`?

The following are all of the code:

    
    
    >>> import matplotlib.pyplot as plt
    >>> import numpy as np
    >>> t = np.arange(256)
    >>> sp = np.fft.fft(np.sin(t))
    >>> freq = np.fft.fftfreq(t.shape[-1])
    >>> plt.plot(freq, sp.real, freq, sp.imag)
    [<matplotlib.lines.Line2D object at 0x1046c8c50>, <matplotlib.lines.Line2D object at 0x1046c8ed0>]
    >>> plt.show()
    Traceback (most recent call last):
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/figure.py", line 1034, in draw
        func(*args)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/axes.py", line 2086, in draw
        a.draw(renderer)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/axis.py", line 1093, in draw
        renderer)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/axis.py", line 1042, in _get_tick_bboxes
        extent = tick.label1.get_window_extent(renderer)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/text.py", line 754, in get_window_extent
        bbox, info, descent = self._get_layout(self._renderer)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/text.py", line 320, in _get_layout
        ismath=False)
      File "/Users/xujc/.Software/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 158, in get_text_width_height_descent
        width, height, descent = self.gc.get_text_width_height_descent(unicode(s), family, size, weight, style)
    TypeError: must be string, not int
    

![figure](http://i.stack.imgur.com/y9cC5.png)

ps:

    
    
    $python
    Python 2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun  2 2014, 12:48:16)
    [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://binstar.org
    

`matplotlib` version is `1.3.1`.


Answer: Work fine for me, if you click the small ">>>" you will get something like
this:

    
    
    import matplotlib.pyplot as plt
    import numpy as np
    t = np.arange(256)
    sp = np.fft.fft(np.sin(t))
    freq = np.fft.fftfreq(t.shape[-1])
    plt.plot(freq, sp.real, freq, sp.imag)
    
    plt.show()
    

python version

    
    
    Python 2.7.6 (default, Jul  9 2014, 20:49:24) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.38)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    

matplotlib..

    
    
    matplotlib (1.3.1)
    

So try going back to use the mac distribution of python, since changing this
it creates more problems that what it could solve.

I install all libraries with pip. :)

Result:: ![enter image description here](http://i.stack.imgur.com/BddTU.png)

