Grid problem?

When I try to turn on the grid for just one axis, seemingly in perfect accordance with the documentation at
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.grid

it seems like there is a problem. I am able to make a graph, but trying to turn on the grid for just one axis causes an error.

My commands are pasted below.

Am I doing this wrong? I am doing the best I can to follow the documentation exactly.

Thanks for any help!

import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3])
ax.set_xlabel('Hi there')
ax.grid(True, axis='x')

bombayduck:~$ python
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3])

[<matplotlib.lines.Line2D object at 0x1a27e30>]

ax.set_xlabel('Hi there')

<matplotlib.text.Text object at 0x1a58030>

ax.grid(True, axis='x')

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py", line 1823, in grid
   self.xaxis.grid(b, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py", line 965, in grid
   if len(kwargs): artist.setp(tick.gridline,**kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py", line 1169, in setp
   func = getattr(o,funcName)
AttributeError: 'Line2D' object has no attribute 'set_axis'

-dave----------------------------------------------------------------------
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says "What are you doing?" The neuroscientist says "Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!"

When I try to turn on the grid for just one axis, seemingly in perfect accordance with the documentation at
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.grid

it seems like there is a problem. I am able to make a graph, but trying to turn on the grid for just one axis causes an error.

My commands are pasted below.

Am I doing this wrong? I am doing the best I can to follow the documentation exactly.

Thanks for any help!

David,

The problem is that the axis kwarg was added to grid only 9 months ago, and evidently you are running an older version of mpl. If you can upgrade to 1.1.0, grid() will work as advertised.

This is a common problem: we post only the latest documentation, instead of having a posted documentation version for each release version.

To work around this, use ipython to display the docstring (or even the source code) for the particular function or method you want to use.

Eric

···

On 01/11/2012 06:05 AM, David Perlman wrote:

import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3])
ax.set_xlabel('Hi there')
ax.grid(True, axis='x')

bombayduck:~$ python
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot([1,2,3])

[<matplotlib.lines.Line2D object at 0x1a27e30>]

ax.set_xlabel('Hi there')

<matplotlib.text.Text object at 0x1a58030>

ax.grid(True, axis='x')

Traceback (most recent call last):
  File "<stdin>", line 1, in<module>
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py", line 1823, in grid
    self.xaxis.grid(b, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py", line 965, in grid
    if len(kwargs): artist.setp(tick.gridline,**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/artist.py", line 1169, in setp
    func = getattr(o,funcName)
AttributeError: 'Line2D' object has no attribute 'set_axis'

-dave----------------------------------------------------------------------
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says "What are you doing?" The neuroscientist says "Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!"

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users