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

Skip to content

Commit d08f739

Browse files
authored
Merge pull request #25747 from anntzer/dad
Tweak axis_direction demo.
2 parents 558f111 + 7aa6ecf commit d08f739

File tree

2 files changed

+31
-53
lines changed

2 files changed

+31
-53
lines changed

galleries/examples/axisartist/demo_axis_direction.py

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,74 +18,52 @@
1818

1919
def setup_axes(fig, rect):
2020
"""Polar projection, but in a rectangular box."""
21-
2221
# 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)
5743
axis.label.set_text(r"$\theta = 30^{\circ}$")
5844
axis.label.set_visible(True)
59-
6045
return axis
6146

6247

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)
6550
axis.label.set_text(r"$r = 6$")
6651
axis.label.set_visible(True)
67-
6852
return axis
6953

7054

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")
7456

7557
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)
7860
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)
8262

8363
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)
8666
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)
9068

9169
plt.show()

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def clear(self):
440440

441441
# Init gridlines before clear() as clear() calls grid().
442442
self.gridlines = gridlines = GridlinesCollection(
443-
None, transform=self.transData,
443+
[], transform=self.transData,
444444
colors=mpl.rcParams['grid.color'],
445445
linestyles=mpl.rcParams['grid.linestyle'],
446446
linewidths=mpl.rcParams['grid.linewidth'])

0 commit comments

Comments
 (0)