Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/example_opendrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
import xarray as xr
import trajan as ta

import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

#%%
# Demonstrating how a trajectory dataset (from OpenDrift)
# can be analysed and plotted with Trajan
Expand Down
8 changes: 4 additions & 4 deletions trajan/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ def set_up_map(self, kwargs_d=None, **kwargs):
else:
fig = plt.figure(figsize=(figsize, figsize * aspect_ratio))

# fig.canvas.draw() # maybe needed?
plt.tight_layout()

else:
fig = plt.gcf()
if len(fig.axes) > 0:
Expand All @@ -133,6 +130,8 @@ def set_up_map(self, kwargs_d=None, **kwargs):
lscale=land,
globe=crs.globe)

fig.tight_layout()

return ax

def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -167,7 +166,8 @@ def lines(self, *args, **kwargs):
# using self.ds.traj.tlon/tlat
x = self.ds.traj.tx.values.T
y = self.ds.traj.ty.values.T
dcrs = self.ds.traj.ccrs
#dcrs = self.ds.traj.ccrs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gauteh This seems to be the reason for the shifted trajectories on figures. I reproduced the same locally after updating Matplotlib to 3.11
https://matplotlib.org/stable/release/prev_whats_new/whats_new_3.11.0.html

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... but won't this only work if the dataset is in geographic coordinates? tx/ty could be in any coordinates (UTM..). Cartesian (no CRS given) is a separate branch, so those should not be affected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it would be more appropriate to use tlon/tlat, but not if cartesian.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit worrying that dcrs is inaccurate.

@knutfrode knutfrode Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this only happens from Matplotlib 3.11, I suspect it is something that should be updated in Cartopy.
See e.g.
SciTools/cartopy#2682

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we need to do something in Trajan.
There are many fundamental changes in Matplotlib 3.11, e.g.:

When closing a shown figure window, the related figure is reset to the standalone state, i.e., it's not visible to pyplot anymore, but if you still hold a reference to it, you can continue to work with it (e.g. do fig.savefig(), or re-add it to pyplot with plt.figure(fig) and then show it again).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Anyway, maybe it's a good compromise to use tlon/tlat for now, then it makes sense conceptually. I can take a look at that later.

dcrs = self.gcrs

cartesian = self.__cartesian__

Expand Down
Loading