2
2
An experimental support for curvilinear grid.
3
3
"""
4
4
5
- import functools
6
-
7
5
# TODO :
8
6
# see if tick_iterator method can be simplified by reusing the parent method.
9
7
8
+ import functools
9
+
10
10
import numpy as np
11
11
12
+ import matplotlib .patches as mpatches
13
+ from matplotlib .path import Path
12
14
from matplotlib .transforms import IdentityTransform
13
- from . import grid_helper_curvelinear
15
+ import matplotlib .axes as maxes
16
+
17
+ from mpl_toolkits .axes_grid1 .parasite_axes import host_axes_class_factory
18
+
19
+ from . import axislines , grid_helper_curvelinear
14
20
from .axis_artist import AxisArtist
21
+ from .grid_finder import ExtremeFinderSimple
15
22
16
23
17
- class FloatingAxisArtistHelper (grid_helper_curvelinear .FloatingAxisArtistHelper ):
24
+ class FloatingAxisArtistHelper (
25
+ grid_helper_curvelinear .FloatingAxisArtistHelper ):
18
26
pass
19
27
20
28
@@ -25,8 +33,7 @@ def __init__(self, grid_helper, side, nth_coord_ticks=None):
25
33
nth_coord = along which coordinate value varies.
26
34
nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
27
35
"""
28
-
29
- value , nth_coord = grid_helper .get_data_boundary (side ) # return v= 0 , nth=1, extremes of the other coordinate.
36
+ value , nth_coord = grid_helper .get_data_boundary (side )
30
37
super ().__init__ (grid_helper , nth_coord , value , axis_direction = side )
31
38
if nth_coord_ticks is None :
32
39
nth_coord_ticks = nth_coord
@@ -117,9 +124,9 @@ def transform_xy(x, y):
117
124
labels = [l for l , m in zip (labels , mask ) if m ]
118
125
119
126
def f1 ():
120
- dd = np .arctan2 (yy1b - yy1a , xx1b - xx1a ) # angle normal
121
- dd2 = np .arctan2 (yy2b - yy2a , xx2b - xx2a ) # angle tangent
122
- mm = (( yy1b - yy1a ) == 0. ) & (( xx1b - xx1a ) == 0. ) # mask where dd1 is not defined
127
+ dd = np .arctan2 (yy1b - yy1a , xx1b - xx1a ) # angle normal
128
+ dd2 = np .arctan2 (yy2b - yy2a , xx2b - xx2a ) # angle tangent
129
+ mm = (yy1b - yy1a == 0 ) & (xx1b - xx1a == 0 ) # mask not defined dd
123
130
dd [mm ] = dd2 [mm ] + np .pi / 2
124
131
125
132
trans_tick = self .get_tick_transform (axes )
@@ -134,21 +141,15 @@ def f1():
134
141
return f1 (), iter ([])
135
142
136
143
def get_line (self , axes ):
137
-
138
144
self .update_lim (axes )
139
- from matplotlib .path import Path
140
145
k , v = dict (left = ("lon_lines0" , 0 ),
141
146
right = ("lon_lines0" , 1 ),
142
147
bottom = ("
EDBE
lat_lines0" , 0 ),
143
148
top = ("lat_lines0" , 1 ))[self ._side ]
144
-
145
149
xx , yy = self .grid_info [k ][v ]
146
150
return Path (np .column_stack ([xx , yy ]))
147
151
148
152
149
- from .grid_finder import ExtremeFinderSimple
150
-
151
-
152
153
class ExtremeFinderFixed (ExtremeFinderSimple ):
153
154
def __init__ (self , extremes ):
154
155
self ._extremes = extremes
@@ -160,7 +161,6 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
160
161
x1, y1, x2, y2 in image coordinates (0-based)
161
162
nx, ny : number of division in each axis
162
163
"""
163
- #lon_min, lon_max, lat_min, lat_max = self._extremes
164
164
return self ._extremes
165
165
166
166
@@ -183,7 +183,7 @@ def __init__(self, aux_trans, extremes,
183
183
184
184
def get_data_boundary (self , side ):
185
185
"""
186
- return v= 0 , nth=1
186
+ return v=0 , nth=1
187
187
"""
188
188
lon1 , lon2 , lat1 , lat2 = self ._extremes
189
189
return dict (left = (lon1 , 0 ),
@@ -269,20 +269,17 @@ def _update_grid(self, x1, y1, x2, y2):
269
269
else :
270
270
lat_values = np .asarray (lat_levs [:lat_n ]/ lat_factor )
271
271
272
- lon_values0 = lon_values [(lon_min < lon_values ) & (lon_values < lon_max )]
273
- lat_values0 = lat_values [(lat_min < lat_values ) & (lat_values < lat_max )]
274
- lon_lines , lat_lines = grid_finder ._get_raw_grid_lines (lon_values0 ,
275
- lat_values0 ,
276
- lon_min , lon_max ,
277
- lat_min , lat_max )
272
+ lon_lines , lat_lines = grid_finder ._get_raw_grid_lines (
273
+ lon_values [(lon_min < lon_values ) & (lon_values < lon_max )],
274
+ lat_values [(lat_min < lat_values ) & (lat_values < lat_max )],
275
+ lon_min , lon_max , lat_min , lat_max )
278
276
279
277
grid_info ["lon_lines" ] = lon_lines
280
278
grid_info ["lat_lines" ] = lat_lines
281
279
282
- lon_lines , lat_lines = grid_finder ._get_raw_grid_lines (extremes [:2 ],
283
- extremes [2 :],
284
- * extremes )
285
- # lon_min, lon_max, lat_min, lat_max)
280
+ lon_lines , lat_lines = grid_finder ._get_raw_grid_lines (
281
+ extremes [:2 ], extremes [2 :], * extremes )
282
+ # lon_min, lon_max, lat_min, lat_max)
286
283
287
284
grid_info ["lon_lines0" ] = lon_lines
288
285
grid_info ["lat_lines0" ] = lat_lines
@@ -344,7 +341,6 @@ def _gen_axes_patch(self):
344
341
.. note::
345
342
Intended to be overridden by new projection types.
346
343
"""
347
- import matplotlib .patches as mpatches
348
344
grid_helper = self .get_grid_helper ()
349
345
t = grid_helper .get_boundary ()
350
346
return mpatches .Polygon (t )
@@ -386,11 +382,6 @@ def floatingaxes_class_factory(axes_class):
386
382
{'_axes_class_floating' : axes_class })
387
383
388
384
389
- from .axislines import Axes
390
- from mpl_toolkits .axes_grid1 .parasite_axes import host_axes_class_factory
391
-
392
- FloatingAxes = floatingaxes_class_factory (host_axes_class_factory (Axes ))
393
-
394
-
395
- import matplotlib .axes as maxes
385
+ FloatingAxes = floatingaxes_class_factory (
386
+ host_axes_class_factory (axislines .Axes ))
396
387
FloatingSubplot = maxes .subplot_class_factory (FloatingAxes )
0 commit comments