Skip to content

Commit 70d2f5c

Browse files
Rewrite commands as top-level code for make_room_for_ylabel_using_xaxesgrid.py
1 parent c880ebc commit 70d2f5c

File tree

1 file changed

+31
-42
lines changed

1 file changed

+31
-42
lines changed

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,54 @@
77
from mpl_toolkits.axes_grid1 import make_axes_locatable
88
from mpl_toolkits.axes_grid1.axes_divider import make_axes_area_auto_adjustable
99

10-
import matplotlib.pyplot as plt
1110

12-
def ex1():
13-
plt.figure(1)
14-
ax = plt.axes([0, 0, 1, 1])
15-
#ax = plt.subplot(111)
11+
plt.figure()
12+
ax = plt.axes([0, 0, 1, 1])
13+
#ax = plt.subplot(111)
1614

17-
ax.set_yticks([0.5])
18-
ax.set_yticklabels(["very long label"])
15+
ax.set_yticks([0.5])
16+
ax.set_yticklabels(["very long label"])
1917

20-
make_axes_area_auto_adjustable(ax)
21-
22-
ex1()
18+
make_axes_area_auto_adjustable(ax)
2319

2420
###############################################################################
2521

2622

27-
def ex2():
28-
29-
plt.figure(2)
30-
ax1 = plt.axes([0, 0, 1, 0.5])
31-
ax2 = plt.axes([0, 0.5, 1, 0.5])
23+
plt.figure()
24+
ax1 = plt.axes([0, 0, 1, 0.5])
25+
ax2 = plt.axes([0, 0.5, 1, 0.5])
3226

33-
ax1.set_yticks([0.5])
34-
ax1.set_yticklabels(["very long label"])
35-
ax1.set_ylabel("Y label")
27+
ax1.set_yticks([0.5])
28+
ax1.set_yticklabels(["very long label"])
29+
ax1.set_ylabel("Y label")
3630

37-
ax2.set_title("Title")
31+
ax2.set_title("Title")
3832

39-
make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2])
40-
make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2])
41-
42-
ex2()
33+
make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2])
34+
make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2])
4335

4436
###############################################################################
4537

4638

47-
def ex3():
48-
49-
fig = plt.figure(3)
50-
ax1 = plt.axes([0, 0, 1, 1])
51-
divider = make_axes_locatable(ax1)
39+
fig = plt.figure()
40+
ax1 = plt.axes([0, 0, 1, 1])
41+
divider = make_axes_locatable(ax1)
5242

53-
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
54-
ax2.tick_params(labelleft=False)
55-
fig.add_axes(ax2)
43+
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
44+
ax2.tick_params(labelleft=False)
45+
fig.add_axes(ax2)
5646

57-
divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1,
58-
adjust_dirs=["left"])
59-
divider.add_auto_adjustable_area(use_axes=[ax2], pad=0.1,
60-
adjust_dirs=["right"])
61-
divider.add_auto_adjustable_area(use_axes=[ax1, ax2], pad=0.1,
62-
adjust_dirs=["top", "bottom"])
47+
divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1,
48+
adjust_dirs=["left"])
49+
divider.add_auto_adjustable_area(use_axes=[ax2], pad=0.1,
50+
adjust_dirs=["right"])
51+
divider.add_auto_adjustable_area(use_axes=[ax1, ax2], pad=0.1,
52+
adjust_dirs=["top", "bottom"])
6353

64-
ax1.set_yticks([0.5])
65-
ax1.set_yticklabels(["very long label"])
54+
ax1.set_yticks([0.5])
55+
ax1.set_yticklabels(["very long label"])
6656

67-
ax2.set_title("Title")
68-
ax2.set_xlabel("X - Label")
57+
ax2.set_title("Title")
58+
ax2.set_xlabel("X - Label")
6959

70-
ex3()
7160
plt.show()

0 commit comments

Comments
 (0)