Skip to content

Commit c5bc302

Browse files
committed
Shorten setup of axes in simple_axis_pad demo.
The code follows the style in demo_axis_direction. The new version remains reasonably legible, and that setup is not really the point of the example anyways (which is about axis padding). Also remove special handling of underscore which is now unnecessary since usetex already auto-handles that.
1 parent 1c3c32f commit c5bc302

File tree

2 files changed

+19
-41
lines changed

2 files changed

+19
-41
lines changed

galleries/examples/axisartist/demo_axis_direction.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
from matplotlib.projections import PolarAxes
1111
from matplotlib.transforms import Affine2D
1212
import mpl_toolkits.axisartist as axisartist
13-
import mpl_toolkits.axisartist.angle_helper as angle_helper
14-
import mpl_toolkits.axisartist.grid_finder as grid_finder
13+
from mpl_toolkits.axisartist import angle_helper, grid_finder
1514
from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear
1615

1716

1817
def setup_axes(fig, rect):
1918
"""Polar projection, but in a rectangular box."""
2019
# see demo_curvelinear_grid.py for details
2120
grid_helper = GridHelperCurveLinear(
22-
(
23-
Affine2D().scale(np.pi/180., 1.) +
24-
PolarAxes.PolarTransform()
25-
),
21+
Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(),
2622
extreme_finder=angle_helper.ExtremeFinderCycle(
2723
20, 20,
2824
lon_cycle=360, lat_cycle=None,

galleries/examples/axisartist/simple_axis_pad.py

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,29 @@
1111
from matplotlib.projections import PolarAxes
1212
from matplotlib.transforms import Affine2D
1313
import mpl_toolkits.axisartist as axisartist
14-
import mpl_toolkits.axisartist.angle_helper as angle_helper
15-
import mpl_toolkits.axisartist.grid_finder as grid_finder
14+
from mpl_toolkits.axisartist import angle_helper, grid_finder
1615
from mpl_toolkits.axisartist.grid_helper_curvelinear import GridHelperCurveLinear
1716

1817

1918
def setup_axes(fig, rect):
2019
"""Polar projection, but in a rectangular box."""
21-
2220
# 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[:].set_visible(False)
47-
ax1.set_aspect(1.)
48-
ax1.set_xlim(-5, 12)
49-
ax1.set_ylim(-5, 10)
50-
51-
return ax1
21+
grid_helper = GridHelperCurveLinear(
22+
Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(),
23+
extreme_finder=angle_helper.ExtremeFinderCycle(
24+
20, 20,
25+
lon_cycle=360, lat_cycle=None,
26+
lon_minmax=None, lat_minmax=(0, np.inf),
27+
),
28+
grid_locator1=angle_helper.LocatorDMS(12),
29+
grid_locator2=grid_finder.MaxNLocator(5),
30+
tick_formatter1=angle_helper.FormatterDMS(),
31+
)
32+
ax = fig.add_subplot(
33+
rect, axes_class=axisartist.Axes, grid_helper=grid_helper,
34+
aspect=1, xlim=(-5, 12), ylim=(-5, 10))
35+
ax.axis[:].set_visible(False)
36+
return ax
5237

5338

5439
def add_floating_axis1(ax1):
@@ -73,9 +58,6 @@ def add_floating_axis2(ax1):
7358

7459

7560
def ann(ax1, d):
76-
if plt.rcParams["text.usetex"]:
77-
d = d.replace("_", r"\_")
78-
7961
ax1.annotate(d, (0.5, 1), (5, -5),
8062
xycoords="axes fraction", textcoords="offset points",
8163
va="top", ha="center")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy