Skip to content

Commit c880ebc

Browse files
Separate plots using #### in make_room_for_ylabel_using_axesgrid.py
1 parent 09c8381 commit c880ebc

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,65 @@
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
1011

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

13-
import matplotlib.pyplot as plt
17+
ax.set_yticks([0.5])
18+
ax.set_yticklabels(["very long label"])
1419

15-
def ex1():
16-
plt.figure(1)
17-
ax = plt.axes([0, 0, 1, 1])
18-
#ax = plt.subplot(111)
20+
make_axes_area_auto_adjustable(ax)
1921

20-
ax.set_yticks([0.5])
21-
ax.set_yticklabels(["very long label"])
22+
ex1()
2223

23-
make_axes_area_auto_adjustable(ax)
24+
###############################################################################
2425

25-
def ex2():
2626

27-
plt.figure(2)
28-
ax1 = plt.axes([0, 0, 1, 0.5])
29-
ax2 = plt.axes([0, 0.5, 1, 0.5])
27+
def ex2():
3028

31-
ax1.set_yticks([0.5])
32-
ax1.set_yticklabels(["very long label"])
33-
ax1.set_ylabel("Y label")
29+
plt.figure(2)
30+
ax1 = plt.axes([0, 0, 1, 0.5])
31+
ax2 = plt.axes([0, 0.5, 1, 0.5])
3432

35-
ax2.set_title("Title")
33+
ax1.set_yticks([0.5])
34+
ax1.set_yticklabels(["very long label"])
35+
ax1.set_ylabel("Y label")
3636

37-
make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2])
38-
make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2])
37+
ax2.set_title("Title")
3938

40-
def ex3():
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])
4141

42-
fig = plt.figure(3)
43-
ax1 = plt.axes([0, 0, 1, 1])
44-
divider = make_axes_locatable(ax1)
42+
ex2()
4543

46-
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
47-
ax2.tick_params(labelleft=False)
48-
fig.add_axes(ax2)
44+
###############################################################################
4945

50-
divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1,
51-
adjust_dirs=["left"])
52-
divider.add_auto_adjustable_area(use_axes=[ax2], pad=0.1,
53-
adjust_dirs=["right"])
54-
divider.add_auto_adjustable_area(use_axes=[ax1, ax2], pad=0.1,
55-
adjust_dirs=["top", "bottom"])
5646

57-
ax1.set_yticks([0.5])
58-
ax1.set_yticklabels(["very long label"])
47+
def ex3():
5948

60-
ax2.set_title("Title")
61-
ax2.set_xlabel("X - Label")
49+
fig = plt.figure(3)
50+
ax1 = plt.axes([0, 0, 1, 1])
51+
divider = make_axes_locatable(ax1)
6252

63-
ex1()
64-
ex2()
65-
ex3()
53+
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
54+
ax2.tick_params(labelleft=False)
55+
fig.add_axes(ax2)
6656

67-
plt.show()
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"])
63+
64+
ax1.set_yticks([0.5])
65+
ax1.set_yticklabels(["very long label"])
66+
67+
ax2.set_title("Title")
68+
ax2.set_xlabel("X - Label")
69+
70+
ex3()
71+
plt.show()

0 commit comments

Comments
 (0)