Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Closed

Unable to configure grid using axisartist #606

ukch opened this issue Dec 2, 2011 · 2 comments
Assignees

Comments

@ukch
Copy link

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))

@leejjoon
Copy link
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
@leejjoon
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants