Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6803bd9

Browse filesBrowse files
Cleanup demo_curvelinear_grid. (#13395)
2 parents 5639790 + 17204e5 commit 6803bd9
Copy full SHA for 6803bd9

File tree

Expand file treeCollapse file tree

1 file changed

+40
-61
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+40
-61
lines changed

‎examples/axisartist/demo_curvelinear_grid.py

Copy file name to clipboardExpand all lines: examples/axisartist/demo_curvelinear_grid.py
+40-61Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
"""
22
=====================
3-
Demo Curvelinear Grid
3+
Curvilinear grid demo
44
=====================
55
66
Custom grid and ticklines.
77
8-
This example demonstrates how to use GridHelperCurveLinear to define
9-
custom grids and ticklines by applying a transformation on the grid.
10-
This can be used, as showcase on the second plot, to create polar
11-
projections in a rectangular box.
8+
This example demonstrates how to use
9+
`~.grid_helper_curvelinear.GridHelperCurveLinear` to define custom grids and
10+
ticklines by applying a transformation on the grid. This can be used, as
11+
shown on the second plot, to create polar projections in a rectangular box.
1212
"""
1313

1414
import numpy as np
1515

1616
import matplotlib.pyplot as plt
17-
import matplotlib.cbook as cbook
17+
from matplotlib.projections import PolarAxes
18+
from matplotlib.transforms import Affine2D
1819

19-
from mpl_toolkits.axisartist import Subplot
20-
from mpl_toolkits.axisartist import SubplotHost, \
21-
ParasiteAxesAuxTrans
22-
from mpl_toolkits.axisartist.grid_helper_curvelinear import \
23-
GridHelperCurveLinear
20+
from mpl_toolkits.axisartist import (
21+
angle_helper, Subplot, SubplotHost, ParasiteAxesAuxTrans)
22+
from mpl_toolkits.axisartist.grid_helper_curvelinear import (
23+
GridHelperCurveLinear)
2424

2525

2626
def curvelinear_test1(fig):
2727
"""
28-
grid for custom transform.
28+
Grid for custom transform.
2929
"""
3030

3131
def tr(x, y):
@@ -46,89 +46,68 @@ def inv_tr(x, y):
4646

4747
fig.add_subplot(ax1)
4848

49-
xx, yy = tr([3, 6], [5.0, 10.])
49+
xx, yy = tr([3, 6], [5, 10])
5050
ax1.plot(xx, yy, linewidth=2.0)
5151

52-
ax1.set_aspect(1.)
53-
ax1.set_xlim(0, 10.)
54-
ax1.set_ylim(0, 10.)
52+
ax1.set_aspect(1)
53+
ax1.set_xlim(0, 10)
54+
ax1.set_ylim(0, 10)
5555

56-
ax1.axis["t"] = ax1.new_floating_axis(0, 3.)
57-
ax1.axis["t2"] = ax1.new_floating_axis(1, 7.)
56+
ax1.axis["t"] = ax1.new_floating_axis(0, 3)
57+
ax1.axis["t2"] = ax1.new_floating_axis(1, 7)
5858
ax1.grid(True, zorder=0)
5959

6060

61-
import mpl_toolkits.axisartist.angle_helper as angle_helper
62-
63-
from matplotlib.projections import PolarAxes
64-
from matplotlib.transforms import Affine2D
65-
66-
6761
def curvelinear_test2(fig):
6862
"""
69-
polar projection, but in a rectangular box.
63+
Polar projection, but in a rectangular box.
7064
"""
7165

7266
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
7367
# system in degree
74-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
75-
76-
# polar projection, which involves cycle, and also has limits in
68+
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform()
69+
# Polar projection, which involves cycle, and also has limits in
7770
# its coordinates, needs a special method to find the extremes
7871
# (min, max of the coordinate within the view).
79-
80-
# 20, 20 : number of sampling points along x, y direction
81-
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
82-
lon_cycle=360,
83-
lat_cycle=None,
84-
lon_minmax=None,
85-
lat_minmax=(0, np.inf),
86-
)
87-
72+
extreme_finder = angle_helper.ExtremeFinderCycle(
73+
nx=20, ny=20, # Number of sampling points in each direction.
74+
lon_cycle=360, lat_cycle=None,
75+
lon_minmax=None, lat_minmax=(0, np.inf),
76+
)
77+
# Find grid values appropriate for the coordinate (degree, minute, second).
8878
grid_locator1 = angle_helper.LocatorDMS(12)
89-
# Find a grid values appropriate for the coordinate (degree,
90-
# minute, second).
91-
79+
# Use an appropriate formatter. Note that the acceptable Locator and
80+
# Formatter classes are a bit different than that of Matplotlib, which
81+
# cannot directly be used here (this may be possible in the future).
9282
tick_formatter1 = angle_helper.FormatterDMS()
93-
# And also uses an appropriate formatter. Note that,the
94-
# acceptable Locator and Formatter class is a bit different than
95-
# that of mpl's, and you cannot directly use mpl's Locator and
96-
# Formatter here (but may be possible in the future).
97-
98-
grid_helper = GridHelperCurveLinear(tr,
99-
extreme_finder=extreme_finder,
100-
grid_locator1=grid_locator1,
101-
tick_formatter1=tick_formatter1
102-
)
10383

84+
grid_helper = GridHelperCurveLinear(
85+
tr, extreme_finder=extreme_finder,
86+
grid_locator1=grid_locator1, tick_formatter1=tick_formatter1)
10487
ax1 = SubplotHost(fig, 1, 2, 2, grid_helper=grid_helper)
10588

10689
# make ticklabels of right and top axis visible.
10790
ax1.axis["right"].major_ticklabels.set_visible(True)
10891
ax1.axis["top"].major_ticklabels.set_visible(True)
109-
11092
# let right axis shows ticklabels for 1st coordinate (angle)
11193
ax1.axis["right"].get_helper().nth_coord_ticks = 0
11294
# let bottom axis shows ticklabels for 2nd coordinate (radius)
11395
ax1.axis["bottom"].get_helper().nth_coord_ticks = 1
11496

11597
fig.add_subplot(ax1)
11698

99+
ax1.set_aspect(1)
100+
ax1.set_xlim(-5, 12)
101+
ax1.set_ylim(-5, 10)
102+
103+
ax1.grid(True, zorder=0)
104+
117105
# A parasite axes with given transform
118106
ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal")
119107
# note that ax2.transData == tr + ax1.transData
120108
# Anything you draw in ax2 will match the ticks and grids of ax1.
121109
ax1.parasites.append(ax2)
122-
intp = cbook.simple_linear_interpolation
123-
ax2.plot(intp(np.array([0, 30]), 50),
124-
intp(np.array([10., 10.]), 50),
125-
linewidth=2.0)
126-
127-
ax1.set_aspect(1.)
128-
ax1.set_xlim(-5, 12)
129-
ax1.set_ylim(-5, 10)
130-
131-
ax1.grid(True, zorder=0)
110+
ax2.plot(np.linspace(0, 30, 51), np.linspace(10, 10, 51), linewidth=2)
132111

133112

134113
if __name__ == "__main__":

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.