Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Unable to configure grid using axisartist #606

Closed
ukch opened this Issue Dec 2, 2011 · 2 comments

Comments

Projects
None yet
2 participants

ukch commented Dec 2, 2011

Consider the following code:

from pylab import *
import mpl_toolkits.axisartist as AA

fig = figure()
ax = fig.add_subplot(AA.Subplot(fig, 111))
ax.bar(range(3), [10, 20, 30])
ax.set_xticks(range(3))
ax.yaxis.grid()
ax.set_axisbelow(True)
show()

With a non-axisartist Subplot object, this will draw horizontal grid lines underneath the bars. However, this code will not draw a grid at all.

After a bit of reading, I discovered the ax.grid method, so decided to change the code to read:

...
ax.grid(axis="y")
ax.set_axisbelow(True)
show()

This does draw a grid, but it draws it for both axes (ie. the axis keyword is completely ignored). It also draws the grid above the chart (ie. ignoring set_axisbelow(True))

Contributor

leejjoon commented Dec 3, 2011

Drawing grid lines for one axes is impossible with axisartist.
I can think of a few workarounds, but none of them seems to be easy and straight forward. Below is one example.

from pylab import *
import mpl_toolkits.axisartist as AA
#from mpl_toolkits.axes_grid1 import host_subplot

fig = figure(1)

# Use SubplotHost
ax = fig.add_subplot(AA.SubplotHost(fig, 111))

ax.bar(range(3), [10, 20, 30])
ax.set_xticks(range(3))

# create a twinx axes, which will be used to draw gridlines.
ax2 = ax.twinx()
ax.axis["right"].toggle(ticks=True)
ax.axis["right"].line.set_visible(True)
ax2.axis["right"].toggle(all=False)
ax2.axis["right"].line.set_visible(False)

ax2.set_yticks([]) # this removes x-grid lines.
ax2.grid()

ax2.gridlines.set_zorder(0.5) # this puts gridlines below other artists.

show()

@ghost ghost assigned leejjoon Dec 5, 2011

Contributor

leejjoon commented Aug 29, 2012

I am closing this. Note that I opened an related feature request at #608.

@leejjoon leejjoon closed this Aug 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment