2

I just create a subplots using matplotlib and choose its parameters as follows:

fig = plt.figure(figsize=(20, 10))
gs = fig.add_gridspec(2, 5, hspace=0.1, wspace=0.18, height_ratios=[1, 3])
(ax1, ax2, ax3, ax4, ax5), (ax6, ax7, ax8, ax9, ax10) = gs.subplots(sharex='col', sharey='row')

Since I choose sharex='col' and sharey='row', all plots in the subplots share their x and y axis through columns and rows. Considering my subplot has two rows and five columns, I just want to share x and y axis for the second row, and share the x axis for the first row. The question is I don't want to share y-axis for the first row of the subplot. How to do that?

EDIT: I tried following, which removes the sharing of the first row.

for i in [ax1, ax2, ax3, ax4, ax5]:
    i._shared_y_axes.remove(i)

However now, although I define yticks of the first row they are not shown properly. I mean, for each plot y labels should be shown separately with their ytick values. enter image description here

Oguzhan
  • 154
  • 1
  • 9
  • 1
    Does this answer your question? [How to share x axes of two subplots after they have been created](https://stackoverflow.com/questions/42973223/how-to-share-x-axes-of-two-subplots-after-they-have-been-created) – Jody Klymak Jan 28 '22 at 06:35
  • Actually, not totally, I try something (I share in edit part) that remove sharing of the first row of the subplot; however, now the yticks are not seen properly. – Oguzhan Jan 28 '22 at 07:19
  • You need to do it the other way, and do all your sharing manually... – Jody Klymak Jan 28 '22 at 08:14
  • @JodyKlymak what is the other way, creating each axis separately ? – Oguzhan Jan 28 '22 at 10:27
  • Its in the link... Create the axes and then `join` lists of axes you want shared. – Jody Klymak Jan 28 '22 at 10:31

0 Answers0