|
4 | 4 | ===================================
|
5 | 5 |
|
6 | 6 | """
|
| 7 | + |
| 8 | +import matplotlib.pyplot as plt |
| 9 | + |
7 | 10 | from mpl_toolkits.axes_grid1 import make_axes_locatable
|
8 | 11 | from mpl_toolkits.axes_grid1.axes_divider import make_axes_area_auto_adjustable
|
9 | 12 |
|
10 | 13 |
|
11 |
| -if __name__ == "__main__": |
12 |
| - |
13 |
| - import matplotlib.pyplot as plt |
| 14 | +plt.figure() |
| 15 | +ax = plt.axes([0, 0, 1, 1]) |
14 | 16 |
|
15 |
| - def ex1(): |
16 |
| - plt.figure(1) |
17 |
| - ax = plt.axes([0, 0, 1, 1]) |
18 |
| - #ax = plt.subplot(111) |
| 17 | +ax.set_yticks([0.5]) |
| 18 | +ax.set_yticklabels(["very long label"]) |
19 | 19 |
|
20 |
| - ax.set_yticks([0.5]) |
21 |
| - ax.set_yticklabels(["very long label"]) |
| 20 | +make_axes_area_auto_adjustable(ax) |
22 | 21 |
|
23 |
| - make_axes_area_auto_adjustable(ax) |
| 22 | +############################################################################### |
24 | 23 |
|
25 |
| - def ex2(): |
26 | 24 |
|
27 |
| - plt.figure(2) |
28 |
| - ax1 = plt.axes([0, 0, 1, 0.5]) |
29 |
| - ax2 = plt.axes([0, 0.5, 1, 0.5]) |
| 25 | +plt.figure() |
| 26 | +ax1 = plt.axes([0, 0, 1, 0.5]) |
| 27 | +ax2 = plt.axes([0, 0.5, 1, 0.5]) |
30 | 28 |
|
31 |
| - ax1.set_yticks([0.5]) |
32 |
| - ax1.set_yticklabels(["very long label"]) |
33 |
| - ax1.set_ylabel("Y label") |
| 29 | +ax1.set_yticks([0.5]) |
| 30 | +ax1.set_yticklabels(["very long label"]) |
| 31 | +ax1.set_ylabel("Y label") |
34 | 32 |
|
35 |
| - ax2.set_title("Title") |
| 33 | +ax2.set_title("Title") |
36 | 34 |
|
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]) |
| 35 | +make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2]) |
| 36 | +make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2]) |
39 | 37 |
|
40 |
| - def ex3(): |
| 38 | +############################################################################### |
41 | 39 |
|
42 |
| - fig = plt.figure(3) |
43 |
| - ax1 = plt.axes([0, 0, 1, 1]) |
44 |
| - divider = make_axes_locatable(ax1) |
45 | 40 |
|
46 |
| - ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1) |
47 |
| - ax2.tick_params(labelleft=False) |
48 |
| - fig.add_axes(ax2) |
| 41 | +fig = plt.figure() |
| 42 | +ax1 = plt.axes([0, 0, 1, 1]) |
| 43 | +divider = make_axes_locatable(ax1) |
49 | 44 |
|
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"]) |
| 45 | +ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1) |
| 46 | +ax2.tick_params(labelleft=False) |
| 47 | +fig.add_axes(ax2) |
56 | 48 |
|
57 |
| - ax1.set_yticks([0.5]) |
58 |
| - ax1.set_yticklabels(["very long label"]) |
| 49 | +divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1, |
| 50 | + adjust_dirs=["left"]) |
| 51 | +divider.add_auto_adjustable_area(use_axes=[ax2], pad=0.1, |
| 52 | + adjust_dirs=["right"]) |
| 53 | +divider.add_auto_adjustable_area(use_axes=[ax1, ax2], pad=0.1, |
| 54 | + adjust_dirs=["top", "bottom"]) |
59 | 55 |
|
60 |
| - ax2.set_title("Title") |
61 |
| - ax2.set_xlabel("X - Label") |
| 56 | +ax1.set_yticks([0.5]) |
| 57 | +ax1.set_yticklabels(["very long label"]) |
62 | 58 |
|
63 |
| - ex1() |
64 |
| - ex2() |
65 |
| - ex3() |
| 59 | +ax2.set_title("Title") |
| 60 | +ax2.set_xlabel("X - Label") |
66 | 61 |
|
67 |
| - plt.show() |
| 62 | +plt.show() |
0 commit comments