'how to share axis just for specific row in subplots
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|