Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2599a0e

Browse files
committed
gridspec supports grid of different cell sizes
svn path=/trunk/matplotlib/; revision=8323
1 parent 412e58e commit 2599a0e

3 files changed

Lines changed: 236 additions & 91 deletions

File tree

doc/users/gridspec.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,23 @@ parameters are set to that of the locataion of the given SubplotSpec. ::
129129
.. plot:: users/plotting/examples/demo_gridspec04.py
130130

131131

132+
GridSpec with Varying Cell Sizes
133+
================================
134+
135+
By default, GridSpec creates cells of equal sizes. You can adjust
136+
relative heights and widths of rows and columns. Note that absolute
137+
values are meaningless, onlt their relative ratios matter. ::
138+
139+
gs = gridspec.GridSpec(2, 2,
140+
width_ratios=[1,2],
141+
height_ratios=[4,1]
142+
)
143+
144+
ax1 = plt.subplot(gs[0])
145+
ax2 = plt.subplot(gs[1])
146+
ax3 = plt.subplot(gs[2])
147+
ax4 = plt.subplot(gs[3])
148+
149+
150+
.. plot:: users/plotting/examples/demo_gridspec05.py
151+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib.gridspec as gridspec
3+
4+
def make_ticklabels_invisible(fig):
5+
for i, ax in enumerate(fig.axes):
6+
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
7+
for tl in ax.get_xticklabels() + ax.get_yticklabels():
8+
tl.set_visible(False)
9+
10+
11+
12+
f = plt.figure()
13+
14+
gs = gridspec.GridSpec(2, 2,
15+
width_ratios=[1,2],
16+
height_ratios=[4,1]
17+
)
18+
19+
ax1 = plt.subplot(gs[0])
20+
ax2 = plt.subplot(gs[1])
21+
ax3 = plt.subplot(gs[2])
22+
ax4 = plt.subplot(gs[3])
23+
24+
make_ticklabels_invisible(f)
25+
plt.show()
26+

0 commit comments

Comments
 (0)