Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f296db

Browse files
authored
Merge pull request #27373 from anntzer/gfi
Transpose grid_finder tick representation.
2 parents f088368 + a4fd8d3 commit 8f296db

File tree

2 files changed

+27
-52
lines changed

2 files changed

+27
-52
lines changed

lib/mpl_toolkits/axisartist/grid_finder.py

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def iter_major():
8282
for nth_coord, show_labels in [
8383
(self.nth_coord_ticks, True), (1 - self.nth_coord_ticks, False)]:
8484
gi = self.grid_helper._grid_info[["lon", "lat"][nth_coord]]
85-
for (xy, angle_normal), l in zip(
86-
gi["tick_locs"][side], gi["tick_labels"][side]):
87-
yield xy, angle_normal, angle_tangent, (l if show_labels else "")
85+
for tick in gi["ticks"][side]:
86+
yield (*tick["loc"], angle_tangent,
87+
(tick["label"] if show_labels else ""))
8888

8989
return iter_major(), iter([])
9090

@@ -321,12 +321,8 @@ def get_tick_iterator(self, nth_coord, axis_side, minor=False):
321321
angle_tangent = dict(left=90, right=90, bottom=0, top=0)[axis_side]
322322
lon_or_lat = ["lon", "lat"][nth_coord]
323323
if not minor: # major ticks
324-
for (xy, angle_normal), l in zip(
325-
self._grid_info[lon_or_lat]["tick_locs"][axis_side],
326-
self._grid_info[lon_or_lat]["tick_labels"][axis_side]):
327-
yield xy, angle_normal, angle_tangent, l
324+
for tick in self._grid_info[lon_or_lat]["ticks"][axis_side]:
325+
yield *tick["loc"], angle_tangent, tick["label"]
328326
else:
329-
for (xy, angle_normal), l in zip(
330-
self._grid_info[lon_or_lat]["tick_locs"][axis_side],
331-
self._grid_info[lon_or_lat]["tick_labels"][axis_side]):
332-
yield xy, angle_normal, angle_tangent, ""
327+
for tick in self._grid_info[lon_or_lat]["ticks"][axis_side]:
328+
yield *tick["loc"], angle_tangent, ""

0 commit comments

Comments
 (0)