Skip to content

Commit 58fdba7

Browse files
committed
- add scatter and event_map
1 parent e50d3fa commit 58fdba7

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/py_eddy_tracker/observations/network.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,86 @@ def scatter_timeline(
407407
mappables["scatter"] = ax.scatter(self.time, y, **kwargs)
408408
return mappables
409409

410+
def event_map(self, ax, **kwargs):
411+
"""Add the merging and splitting events """
412+
j = 0
413+
mappables = dict()
414+
symbol_kw = dict(
415+
markersize=10,
416+
color="k",
417+
)
418+
symbol_kw.update(kwargs)
419+
symbol_kw_split = symbol_kw.copy()
420+
symbol_kw_split["markersize"] += 5
421+
for i, b0, b1 in self.iter_on("segment"):
422+
nb = i.stop - i.start
423+
if nb == 0:
424+
continue
425+
event_kw = dict(color=self.COLORS[j % self.NB_COLORS], ls="-", **kwargs)
426+
i_n, i_p = (
427+
self.next_obs[i.stop - 1],
428+
self.previous_obs[i.start],
429+
)
430+
431+
if i_n != -1:
432+
y0, y1 = self.lat[i.stop - 1], self.lat[i_n]
433+
x0, x1 = self.lon[i.stop - 1], self.lon[i_n]
434+
ax.plot((x0, x1), (y0, y1), **event_kw)[0]
435+
ax.plot(x0, y0, marker="s", **symbol_kw)[0]
436+
if i_p != -1:
437+
y0, y1 = self.lat[i.start], self.lat[i_p]
438+
x0, x1 = self.lon[i.start], self.lon[i_p]
439+
ax.plot((x0, x1), (y0, y1), **event_kw)[0]
440+
ax.plot(x0, y0, marker="*", **symbol_kw_split)[0]
441+
442+
j += 1
443+
return mappables
444+
445+
def scatter(
446+
self,
447+
ax,
448+
name="time",
449+
s=25,
450+
factor=1,
451+
ref=None,
452+
edgecolor_cycle=None,
453+
cmap="Spectral_r",
454+
**kwargs,
455+
):
456+
"""
457+
This function will scatter the path of each trajectory
458+
459+
:param matplotlib.axes.Axes ax: ax to draw
460+
:param float,int ref: if defined, all coordinates will be wrapped with ref like west boundary
461+
:param dict kwargs: keyword arguments for Axes.plot
462+
:return: a list of matplotlib mappables
463+
"""
464+
mappables = dict()
465+
nb_colors = len(edgecolor_cycle) if edgecolor_cycle != None else None
466+
x = self.longitude
467+
if ref is not None:
468+
x = (x - ref) % 360 + ref
469+
kwargs = kwargs.copy()
470+
if nb_colors:
471+
edgecolors = list()
472+
seg_previous = self.segment[0]
473+
j = 0
474+
for seg in self.segment:
475+
if seg != seg_previous:
476+
j += 1
477+
edgecolors.append(edgecolor_cycle[j % nb_colors])
478+
seg_previous = seg
479+
mappables["edges"] = ax.scatter(
480+
x, self.latitude, edgecolor=edgecolors, **kwargs
481+
)
482+
kwargs.pop("linewidths", None)
483+
kwargs["lw"] = 0
484+
if name is not None and "c" not in kwargs:
485+
v = self.parse_varname(name)
486+
kwargs["c"] = v * factor
487+
mappables["scatter"] = ax.scatter(x, self.latitude, **kwargs)
488+
return mappables
489+
410490
def insert_virtual(self):
411491
# TODO
412492
pass

0 commit comments

Comments
 (0)