|
18 | 18 |
|
19 | 19 | def setup_axes(fig, rect):
|
20 | 20 | """Polar projection, but in a rectangular box."""
|
21 |
| - |
22 | 21 | # see demo_curvelinear_grid.py for details
|
23 |
| - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() |
24 |
| - |
25 |
| - extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, |
26 |
| - lon_cycle=360, |
27 |
| - lat_cycle=None, |
28 |
| - lon_minmax=None, |
29 |
| - lat_minmax=(0, np.inf), |
30 |
| - ) |
31 |
| - |
32 |
| - grid_locator1 = angle_helper.LocatorDMS(12) |
33 |
| - grid_locator2 = grid_finder.MaxNLocator(5) |
34 |
| - |
35 |
| - tick_formatter1 = angle_helper.FormatterDMS() |
36 |
| - |
37 |
| - grid_helper = GridHelperCurveLinear(tr, |
38 |
| - extreme_finder=extreme_finder, |
39 |
| - grid_locator1=grid_locator1, |
40 |
| - grid_locator2=grid_locator2, |
41 |
| - tick_formatter1=tick_formatter1 |
42 |
| - ) |
43 |
| - |
44 |
| - ax1 = fig.add_subplot( |
45 |
| - rect, axes_class=axisartist.Axes, grid_helper=grid_helper) |
46 |
| - ax1.axis[:].toggle(ticklabels=False) |
47 |
| - |
48 |
| - ax1.set_aspect(1.) |
49 |
| - ax1.set_xlim(-5, 12) |
50 |
| - ax1.set_ylim(-5, 10) |
51 |
| - |
52 |
| - return ax1 |
53 |
| - |
54 |
| - |
55 |
| -def add_floating_axis1(ax1): |
56 |
| - ax1.axis["lat"] = axis = ax1.new_floating_axis(0, 30) |
| 22 | + grid_helper = GridHelperCurveLinear( |
| 23 | + Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(), |
| 24 | + extreme_finder=angle_helper.ExtremeFinderCycle( |
| 25 | + 20, 20, |
| 26 | + lon_cycle=360, lat_cycle=None, |
| 27 | + lon_minmax=None, lat_minmax=(0, np.inf), |
| 28 | + ), |
| 29 | + grid_locator1=angle_helper.LocatorDMS(12), |
| 30 | + grid_locator2=grid_finder.MaxNLocator(5), |
| 31 | + tick_formatter1=angle_helper.FormatterDMS(), |
| 32 | + ) |
| 33 | + ax = fig.add_subplot( |
| 34 | + rect, axes_class=axisartist.Axes, grid_helper=grid_helper, |
| 35 | + aspect=1, xlim=(-5, 12), ylim=(-5, 10)) |
| 36 | + ax.axis[:].toggle(ticklabels=False) |
| 37 | + ax.grid(color=".9") |
| 38 | + return ax |
| 39 | + |
| 40 | + |
| 41 | +def add_floating_axis1(ax): |
| 42 | + ax.axis["lat"] = axis = ax.new_floating_axis(0, 30) |
57 | 43 | axis.label.set_text(r"$\theta = 30^{\circ}$")
|
58 | 44 | axis.label.set_visible(True)
|
59 |
| - |
60 | 45 | return axis
|
61 | 46 |
|
62 | 47 |
|
63 |
| -def add_floating_axis2(ax1): |
64 |
| - ax1.axis["lon"] = axis = ax1.new_floating_axis(1, 6) |
| 48 | +def add_floating_axis2(ax): |
| 49 | + ax.axis["lon"] = axis = ax.new_floating_axis(1, 6) |
65 | 50 | axis.label.set_text(r"$r = 6$")
|
66 | 51 | axis.label.set_visible(True)
|
67 |
| - |
68 | 52 | return axis
|
69 | 53 |
|
70 | 54 |
|
71 |
| -fig = plt.figure(figsize=(8, 4)) |
72 |
| -fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99, |
73 |
| - wspace=0.01, hspace=0.01) |
| 55 | +fig = plt.figure(figsize=(8, 4), layout="constrained") |
74 | 56 |
|
75 | 57 | for i, d in enumerate(["bottom", "left", "top", "right"]):
|
76 |
| - ax1 = setup_axes(fig, rect=241++i) |
77 |
| - axis = add_floating_axis1(ax1) |
| 58 | + ax = setup_axes(fig, rect=241+i) |
| 59 | + axis = add_floating_axis1(ax) |
78 | 60 | axis.set_axis_direction(d)
|
79 |
| - ax1.annotate(d, (0, 1), (5, -5), |
80 |
| - xycoords="axes fraction", textcoords="offset points", |
81 |
| - va="top", ha="left") |
| 61 | + ax.set(title=d) |
82 | 62 |
|
83 | 63 | for i, d in enumerate(["bottom", "left", "top", "right"]):
|
84 |
| - ax1 = setup_axes(fig, rect=245++i) |
85 |
| - axis = add_floating_axis2(ax1) |
| 64 | + ax = setup_axes(fig, rect=245+i) |
| 65 | + axis = add_floating_axis2(ax) |
86 | 66 | axis.set_axis_direction(d)
|
87 |
| - ax1.annotate(d, (0, 1), (5, -5), |
88 |
| - xycoords="axes fraction", textcoords="offset points", |
89 |
| - va="top", ha="left") |
| 67 | + ax.set(title=d) |
90 | 68 |
|
91 | 69 | plt.show()
|
0 commit comments