8000 Cleanup the GridSpec demos. by anntzer · Pull Request #12156 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Cleanup the GridSpec demos. #12156

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

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/users/prev_whats_new/whats_new_1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Jae-Joon Lee has written :mod:`~matplotlib.gridspec`, a new module for
doing complex subplot layouts, featuring row and column spans and
more. See :doc:`/tutorials/intermediate/gridspec` for a tutorial overview.

.. figure:: ../../gallery/userdemo/images/sphx_glr_demo_gridspec01_000.png
.. figure:: ../../gallery/userdemo/images/sphx_glr_demo_gridspec01_001.png
:target: ../../gallery/userdemo/demo_gridspec01.html
:align: center
:scale: 50
Expand Down
17 changes: 10 additions & 7 deletions examples/userdemo/demo_gridspec01.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"""
===============
Demo Gridspec01
===============
=================
subplot2grid demo
=================

This example demonstrates the use of `plt.subplot2grid` to generate subplots.
Using `GridSpec`, as demonstrated in :doc:`/gallery/userdemo/demo_gridspec03`
is generally preferred.
"""

import matplotlib.pyplot as plt


def make_ticklabels_invisible(fig):
def annotate_axes(fig):
for i, ax in enumerate(fig.axes):
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
ax.tick_params(labelbottom=False, labelleft=False)


fig = plt.figure(0)
fig = plt.figure()
ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3)
ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
ax4 = plt.subplot2grid((3, 3), (2, 0))
ax5 = plt.subplot2grid((3, 3), (2, 1))

fig.suptitle("subplot2grid")
make_ticklabels_invisible(fig)
annotate_axes(fig)

plt.show()
51 changes: 32 additions & 19 deletions examples/userdemo/demo_gridspec03.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
"""
===============
Demo Gridspec03
===============

=============
GridSpec demo
=============

This example demonstrates the use of `GridSpec` to generate subplots,
the control of the relative sizes of subplots with *width_ratios* and
*height_ratios*, and the control of the spacing around and between subplots
using subplot params (*left*, *right*, *bottom*, *top*, *wspace*, and
*hspace*).
"""

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec


def make_ticklabels_invisible(fig):
def annotate_axes(fig):
for i, ax in enumerate(fig.axes):
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
ax.tick_params(labelbottom=False, labelleft=False)


# demo 3 : gridspec with subplotpars set.

fig = plt.figure()
fig.suptitle("Controlling subplot sizes with width_ratios and height_ratios")

gs = GridSpec(2, 2, width_ratios=[1, 2], 10000 height_ratios=[4, 1])
ax1 = fig.add_subplot(gs[0])
ax2 = fig.add_subplot(gs[1])
ax3 = fig.add_subplot(gs[2])
ax4 = fig.add_subplot(gs[3])

fig.suptitle("GridSpec w/ different subplotpars")
annotate_axes(fig)


fig = plt.figure()
fig.suptitle("Controlling spacing around and between subplots")

gs1 = GridSpec(3, 3)
gs1.update(left=0.05, right=0.48, wspace=0.05)
ax1 = plt.subplot(gs1[:-1, :])
ax2 = plt.subplot(gs1[-1, :-1])
ax3 = plt.subplot(gs1[-1, -1])
gs1 = GridSpec(3, 3, left=0.05, right=0.48, wspace=0.05)
ax1 = fig.add_subplot(gs1[:-1, :])
ax2 = fig.add_subplot(gs1[-1, :-1])
ax3 = fig.add_subplot(gs1[-1, -1])

gs2 = GridSpec(3, 3)
gs2.update(left=0.55, right=0.98, hspace=0.05)
ax4 = plt.subplot(gs2[:, :-1])
ax5 = plt.subplot(gs2[:-1, -1])
ax6 = plt.subplot(gs2[-1, -1])
gs2 = GridSpec(3, 3, left=0.55, right=0.98, hspace=0.05)
ax4 = fig.add_subplot(gs2[:, :-1])
ax5 = fig.add_subplot(gs2[:-1, -1])
ax6 = fig.add_subplot(gs2[-1, -1])

make_ticklabels_invisible(fig)
annotate_axes(fig)

plt.show()
28 changes: 0 additions & 28 deletions examples/userdemo/demo_gridspec05.py

This file was deleted.

14 changes: 8 additions & 6 deletions examples/userdemo/demo_gridspec06.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
===============
Demo Gridspec06
===============
r"""
================
Nested GridSpecs
================

This example demonstrates the use of nested `GridSpec`\s.
"""

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
Expand All @@ -26,15 +28,15 @@ def squiggle_xy(a, b, c, d):
a = i // 4 + 1
b = i % 4 + 1
for j, (c, d) in enumerate(product(range(1, 4), repeat=2)):
ax = plt.Subplot(fig, inner_grid[j])
ax = fig.add_subplot(inner_grid[j])
ax.plot(*squiggle_xy(a, b, c, d))
ax.set_xticks([])
ax.set_yticks([])
fig.add_subplot(ax)

all_axes = fig.get_axes()

#show only the outside spines
# show only the outside spines
for ax in all_axes:
for sp in ax.spines.values():
sp.set_visible(False)
Expand Down
0