1

I'm doing a multi panel plot using gridspec, but I'm having a few issues. I want each row to share a different y axis and each column to share a different x axis. Or, in other words, to share x per row and share y per column. I also want to add a label to each of these axis. Here is an example of what I'm talking about along with the code that made that (minus the axis labels I want): sample axis sharing
(source: matplotlib.org)

# row and column sharing
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
ax1.plot(x, y)
ax1.set_title('Sharing x per column, y per row')
ax2.scatter(x, y)
ax3.scatter(x, 2 * y ** 2 - 1, color='r')
ax4.plot(x, 2 * y ** 2 - 1, color='r')

However I can't exactly use this implementation because I am using subplot2grid as I need to choose the specific positions and dimensions of each plot. I've tried using something sharex=ax1 and sharey = ax1 in the subplot2grid call to no avail. Here is the relevant portion of my code:

ax1 = plt.subplot2grid((8,8), (2,0), colspan=2, rowspan=2)
ax2 = plt.subplot2grid((8,8), (4,0), colspan=2, rowspan=2)
ax3 = plt.subplot2grid((8,8), (6,0), colspan=2, rowspan=2)
ax4 = plt.subplot2grid((8,8), (2,2), colspan=2, rowspan=2)
ax5 = plt.subplot2grid((8,8), (4,2), colspan=2, rowspan=2)
ax6 = plt.subplot2grid((8,8), (2,4), colspan=2, rowspan=2)
ax7 = plt.subplot2grid((8,8), (1,0), colspan=2, rowspan=1)
ax8 = plt.subplot2grid((8,8), (1,2), colspan=2, rowspan=1)
ax9 = plt.subplot2grid((8,8), (1,4), colspan=2, rowspan=1)
ax10 = plt.subplot2grid((8,8), (2,6), colspan=1, rowspan=2)
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
user1679198
  • 63
  • 4
  • 9
  • Using (for example) `sharex=ax1` and/or `sharey=ax1` in the definition of `ax2` or any other of your calls should work (works for me). – Ajean Sep 13 '14 at 01:09

1 Answers1

0

In contrast to normal subplots, subplots from using sharex/sharey=ax with subplot2grid or GridSpec will not only share the range, but also the ticks.

To configure ticks for each subplot separately you need plt.setp(ax.get_xticklabels(), visible=False), see GridSpec with shared axes in Python for more details.

Community
  • 1
  • 1
germannp
  • 197
  • 4
  • 15