I'm a novice programmer and my hunch is that this error is due to some sort of installation or version problem, but I have no idea what. I'm running python 2.7 on OS 10.8, and just installed numpy 1.12.0 and matplotlib-1.5.1 today in an attempt to construct a heatmap.
I'm trying to run this example from the matplotlib site (http://matplotlib.org/examples/api/image_zcoord.html):
"""
Show how to modify the coordinate formatter to report the image "z"
value of the nearest pixel given x and y
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
X = 10*np.random.rand(5, 3)
fig, ax = plt.subplots()
ax.imshow(X, cmap=cm.jet, interpolation='nearest')
numrows, numcols = X.shape
def format_coord(x, y):
col = int(x + 0.5)
row = int(y + 0.5)
if col >= 0 and col < numcols and row >= 0 and row < numrows:
z = X[row, col]
return 'x=%1.4f, y=%1.4f, z=%1.4f' % (x, y, z)
else:
return 'x=%1.4f, y=%1.4f' % (x, y)
ax.format_coord = format_coord
plt.show()
A plot window appears, but nothing is displayed, and the mouseover coordinates kind of "stack" instead of refreshing and quickly become illegible. I also get this error in terminal:
AttributeError: 'numpy.ndarray' object has no attribute 'as_rgba_str'
Other, similar examples from the matplotlib site also exhibit similar behavior. Of course, please let me know if this is a duplicate (I tried to search for an answer but didn't find anything similar to my problem, but I also might just not know what to search for).
If it is an installation error, instructions on how to fix it or a point in the right direction with detailed instructions would be much appreciated. Thank you!
Edit: Here's the traceback before the error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d- py2.7-macosx-10.8-x86_64.egg/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/figure.py", line 1262, in draw
renderer, self, dsu, self.suppressComposite)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/axes/_base.py", line 2355, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/image.py", line 472, in draw
renderer.draw_image(gc, l, b, im)
File "/usr/local/lib/python2.7/site-packages/matplotlib-1.5.1+1539.g1111c1d-py2.7-macosx-10.8-x86_64.egg/matplotlib/backends/backend_macosx.py", line 113, in draw_image
nrows, ncols, data = im.as_rgba_str()
AttributeError: 'numpy.ndarray' object has no attribute 'as_rgba_str'