Open jerabaul29 opened 1 month ago
linestyle="none", marker="."
A simple workaround to avoid the ugly line is to use linestyle="none", marker=".", markersize=10
or similar. For example:
# %%
plt.figure()
proj = ccrs.PlateCarree(central_longitude=179.0)
ax = plt.axes(projection=proj)
xr_data.traj.plot(linestyle="none", marker=".", markersize=10, color="red")
ax.coastlines()
lon1, lon2, lat1, lat2 = 155, 210, -25.0, 5.0
ax.set_extent([lon1, lon2, lat1, lat2], crs=ccrs.PlateCarree())
plt.show()
# %%
generates something that looks like:
A few notes:
it seems that quite a bit of the trajan "nicely plotting" disappears; for example, if I do not have the ax.coastlines()
part, there are no map information at all. Not sure why, and this happens also if I put some ax=ax
in the trajan plot call.
if not setting the limits, i.e. the
lon1, lon2, lat1, lat2 = 155, 210, -25.0, 5.0
ax.set_extent([lon1, lon2, lat1, lat2], crs=ccrs.PlateCarree())
part, then the plot looks like
I see a few things that could be considered here; what are your thoughts / what would you like me to give a try at implementing @gauteh ? :)
implementing a scatter rather than line plot in trajan; not sure if this could be for example a xr_data.traj.scatter(color="red")
, or making sure the xr_data.traj.plot(color="red")
behaves well with an extra linestyle="none"
argument (i.e. making sure that extra coast / land etc information is still rendered then)?
I could also write some simple function that goes through the lon time series for each drifter to i) detect likely wrapping, ii) "unwrap" the likely wrapping; by iii) providing an extra flag (unwrap_lon
for example?) to traj.plot
to call this unwrapping on the longitude data, we could avoid the "ugly" lines?
Just a quick comment now, we already have scatter: https://github.com/OpenDrift/trajan/blob/73260cc1a1b737a140dae02d7c52d5713e341851/trajan/plot/__init__.py#L201 . ds.traj.plot() is short for ds.traj.plot.lines().
@gauteh thank you for the tips about scatter! :)
By running
xr_data.traj.plot.scatter()
plt.show()
I get this plotted, fast:
So this is very nice and nearly fits my need :) . I think the "only" issue is that now all trajectories are in teh same color, but I am not sure if there is an easy way around with the scatter function.
trajan uses a lower alpha if there are "many" trajectories, but in theory it should be possible to do that exactly as with the lines
function. I don't think it is implemented yet though: https://github.com/OpenDrift/trajan/blob/main/trajan/plot/__init__.py#L172
Plots crossing the "-180/+180" wrapping longitude line have "ugly" lines appearing on them. Consider for example the dummy trajectory:
This generates a plot that looks like:
Would this make sense to improve on in trajan?
I think that there are several aspects to consider:
the "ugly line" in itself: this could be removed so that the trajectory plot only goes from the left side, to the "left end", and then to the "right end" to the right side, without the "ugly line".
in cases when there is only information around the -180/+180 area, and no information / lines e.g. around longitude 0, the projection for the plot could be centered around the "center of mass" of the trajectories, rather than around longitude 0. Note that this would only solve the problem if having for example only data between [175; wrapped 185], but this would not help if there are "global" trajectories running globally around Earth.
I am looking a bit into this, I can try to populate this issue as I dig in fixes in cartopy and similar.