Skip to content

Using self.gcrs instead of self.ds.traj.ccrs for plot transform, as t… - #210

Merged
knutfrode merged 1 commit into
OpenDrift:mainfrom
knutfrode:dev
Jun 25, 2026
Merged

Using self.gcrs instead of self.ds.traj.ccrs for plot transform, as t…#210
knutfrode merged 1 commit into
OpenDrift:mainfrom
knutfrode:dev

Conversation

@knutfrode

Copy link
Copy Markdown
Contributor

…he latter gives shifted trajectories

Comment thread trajan/plot/__init__.py
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.

@knutfrode
knutfrode merged commit 194e2b5 into OpenDrift:main Jun 25, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants