@@ -193,25 +193,28 @@ def get_grid_info(self, x1, y1, x2, y2):
193193
194194 grid_info = {
195195 "extremes" : extremes ,
196- "lon_lines" : lon_lines ,
197- "lat_lines" : lat_lines ,
198- "lon" : self ._clip_grid_lines_and_find_ticks (
199- lon_lines , lon_values , lon_levs , bb ),
200- "lat" : self ._clip_grid_lines_and_find_ticks (
201- lat_lines , lat_values , lat_levs , bb ),
196+ # "lon", "lat", filled below.
202197 }
203198
204- tck_labels = grid_info ["lon" ]["tick_labels" ] = {}
205- for direction in ["left" , "bottom" , "right" , "top" ]:
206- levs = grid_info ["lon" ]["tick_levels" ][direction ]
207- tck_labels [direction ] = self ._format_ticks (
208- 1 , direction , lon_factor , levs )
209-
210- tck_labels = grid_info ["lat" ]["tick_labels" ] = {}
211- for direction in ["left" , "bottom" , "right" , "top" ]:
212- levs = grid_info ["lat" ]["tick_levels" ][direction ]
213- tck_labels [direction ] = self ._format_ticks (
214- 2 , direction , lat_factor , levs )
199+ for idx , lon_or_lat , levs , factor , values , lines in [
200+ (1 , "lon" , lon_levs , lon_factor , lon_values , lon_lines ),
201+ (2 , "lat" , lat_levs , lat_factor , lat_values , lat_lines ),
202+ ]:
203+ grid_info [lon_or_lat ] = gi = {
204+ "lines" : [[l ] for l in lines ],
205+ "ticks" : {"left" : [], "right" : [], "bottom" : [], "top" : []},
206+ }
207+ for (lx , ly ), v , level in zip (lines , values , levs ):
208+ all_crossings = _find_line_box_crossings (np .column_stack ([lx , ly ]), bb )
209+ for side , crossings in zip (
210+ ["left" , "right" , "bottom" , "top" ], all_crossings ):
211+ for crossing in crossings :
212+ gi ["ticks" ][side ].append ({"level" : level , "loc" : crossing })
213+ for side in gi ["ticks" ]:
214+ levs = [tick ["level" ] for tick in gi ["ticks" ][side ]]
215+ labels = self ._format_ticks (idx , side , factor , levs )
216+ for tick , label in zip (gi ["ticks" ][side ], labels ):
217+ tick ["label" ] = label
215218
216219 return grid_info
217220
@@ -229,30 +232,6 @@ def _get_raw_grid_lines(self,
229232
230233 return lon_lines , lat_lines
231234
232- def _clip_grid_lines_and_find_ticks (self , lines , values , levs , bb ):
233- gi = {
234- "values" : [],
235- "levels" : [],
236- "tick_levels" : dict (left = [], bottom = [], right = [], top = []),
237- "tick_locs" : dict (left = [], bottom = [], right = [], top = []),
238- "lines" : [],
239- }
240-
241- tck_levels = gi ["tick_levels" ]
242- tck_locs = gi ["tick_locs" ]
243- for (lx , ly ), v , lev in zip (lines , values , levs ):
244- tcks = _find_line_box_crossings (np .column_stack ([lx , ly ]), bb )
245- gi ["levels" ].append (v )
246- gi ["lines" ].append ([(lx , ly )])
247-
248- for tck , direction in zip (tcks ,
249- ["left" , "right" , "bottom" , "top" ]):
250- for t in tck :
251- tck_levels [direction ].append (lev )
252- tck_locs [direction ].append (t )
253-
254- return gi
255-
256235 def set_transform (self , aux_trans ):
257236 if isinstance (aux_trans , Transform ):
258237 self ._aux_transform = aux_trans
0 commit comments