diff --git a/examples/subplots_axes_and_figures/gridspec_nested.py b/examples/subplots_axes_and_figures/gridspec_nested.py index e233e643ec68..75fa34f7b0b9 100644 --- a/examples/subplots_axes_and_figures/gridspec_nested.py +++ b/examples/subplots_axes_and_figures/gridspec_nested.py @@ -24,22 +24,16 @@ def format_axes(fig): gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0]) -ax1 = plt.Subplot(f, gs00[:-1, :]) -f.add_subplot(ax1) -ax2 = plt.Subplot(f, gs00[-1, :-1]) -f.add_subplot(ax2) -ax3 = plt.Subplot(f, gs00[-1, -1]) -f.add_subplot(ax3) - - -gs01 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[1]) - -ax4 = plt.Subplot(f, gs01[:, :-1]) -f.add_subplot(ax4) -ax5 = plt.Subplot(f, gs01[:-1, -1]) -f.add_subplot(ax5) -ax6 = plt.Subplot(f, gs01[-1, -1]) -f.add_subplot(ax6) +ax1 = f.add_subplot(gs00[:-1, :]) +ax2 = f.add_subplot(gs00[-1, :-1]) +ax3 = f.add_subplot(gs00[-1, -1]) + +# the following syntax does the same as the GridSpecFromSubplotSpec call above: +gs01 = gs0[1].subgridspec(3, 3) + +ax4 = f.add_subplot(gs01[:, :-1]) +ax5 = f.add_subplot(gs01[:-1, -1]) +ax6 = f.add_subplot(gs01[-1, -1]) plt.suptitle("GridSpec Inside GridSpec") format_axes(f) diff --git a/tutorials/intermediate/gridspec.py b/tutorials/intermediate/gridspec.py index 48e19545f1c5..df46971cd164 100644 --- a/tutorials/intermediate/gridspec.py +++ b/tutorials/intermediate/gridspec.py @@ -242,7 +242,7 @@ def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): inner_grid = outer_grid[i].subgridspec(3, 3, wspace=0.0, hspace=0.0) a, b = int(i/4)+1, i % 4+1 for j, (c, d) in enumerate(product(range(1, 4), repeat=2)): - ax = plt.Subplot(fig11, inner_grid[j]) + ax = fig11.add_subplot(inner_grid[j]) ax.plot(*squiggle_xy(a, b, c, d)) ax.set_xticks([]) ax.set_yticks([])