22An experimental support for curvilinear grid.
33"""
44
5- import functools
6-
75# TODO :
86# see if tick_iterator method can be simplified by reusing the parent method.
97
8+ import functools
9+
1010import numpy as np
1111
12+ import matplotlib .patches as mpatches
13+ from matplotlib .path import Path
1214from 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
1420from .axis_artist import AxisArtist
21+ from .grid_finder import ExtremeFinderSimple
1522
1623
17- class FloatingAxisArtistHelper (grid_helper_curvelinear .FloatingAxisArtistHelper ):
24+ class FloatingAxisArtistHelper (
25+ grid_helper_curvelinear .FloatingAxisArtistHelper ):
1826 pass
1927
2028
@@ -25,8 +33,7 @@ def __init__(self, grid_helper, side, nth_coord_ticks=None):
2533 nth_coord = along which coordinate value varies.
2634 nth_coord = 0 -> x axis, nth_coord = 1 -> y axis
2735 """
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 )
3037 super ().__init__ (grid_helper , nth_coord , value , axis_direction = side )
3138 if nth_coord_ticks is None :
3239 nth_coord_ticks = nth_coord
@@ -117,9 +124,9 @@ def transform_xy(x, y):
117124 labels = [l for l , m in zip (labels , mask ) if m ]
118125
119126 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
123130 dd [mm ] = dd2 [mm ] + np .pi / 2
124131
125132 trans_tick = self .get_tick_transform (axes )
@@ -134,21 +141,15 @@ def f1():
134141 return f1 (), iter ([])
135142
136143 def get_line (self , axes ):
137-
138144 self .update_lim (axes )
139- from matplotlib .path import Path
140145 k , v = dict (left = ("lon_lines0" , 0 ),
141146 right = ("lon_lines0" , 1 ),
142147 bottom = ("lat_lines0" , 0 ),
143148 top = ("lat_lines0" , 1 ))[self ._side ]
144-
145149 xx , yy = self .grid_info [k ][v ]
146150 return Path (np .column_stack ([xx , yy ]))
147151
148152
149- from .grid_finder import ExtremeFinderSimple
150-
151-
152153class ExtremeFinderFixed (ExtremeFinderSimple ):
153154 def __init__ (self , extremes ):
154155 self ._extremes = extremes
@@ -160,7 +161,6 @@ def __call__(self, transform_xy, x1, y1, x2, y2):
160161 x1, y1, x2, y2 in image coordinates (0-based)
161162 nx, ny : number of division in each axis
162163 """
163- #lon_min, lon_max, lat_min, lat_max = self._extremes
164164 return self ._extremes
165165
166166
@@ -183,7 +183,7 @@ def __init__(self, aux_trans, extremes,
183183
184184 def get_data_boundary (self , side ):
185185 """
186- return v= 0 , nth=1
186+ return v=0 , nth=1
187187 """
188188 lon1 , lon2 , lat1 , lat2 = self ._extremes
189189 return dict (left = (lon1 , 0 ),
@@ -269,20 +269,17 @@ def _update_grid(self, x1, y1, x2, y2):
269269 else :
270270 lat_values = np .asarray (lat_levs [:lat_n ]/ lat_factor )
271271
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 )
278276
279277 grid_info ["lon_lines" ] = lon_lines
280278 grid_info ["lat_lines" ] = lat_lines
281279
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)
286283
287284 grid_info ["lon_lines0" ] = lon_lines
288285 grid_info ["lat_lines0" ] = lat_lines
@@ -344,7 +341,6 @@ def _gen_axes_patch(self):
344341 .. note::
345342 Intended to be overridden by new projection types.
346343 """
347- import matplotlib .patches as mpatches
348344 grid_helper = self .get_grid_helper ()
349345 t = grid_helper .get_boundary ()
350346 return mpatches .Polygon (t )
@@ -386,11 +382,6 @@ def floatingaxes_class_factory(axes_class):
386382 {'_axes_class_floating' : axes_class })
387383
388384
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 ))
396387FloatingSubplot = maxes .subplot_class_factory (FloatingAxes )
0 commit comments