Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example of a(n horribly) wrong plot when NOT using nc-time-axis #122

Open
jypeter opened this issue Jan 11, 2023 · 5 comments
Open
Labels
New: Documentation Highlight a new community raised "documentation" issue Type: Documentation

Comments

@jypeter
Copy link

jypeter commented Jan 11, 2023

📚 Documentation

This is a nice and useful extension of cftime and matplolib!

We spent some time this afternoon with @oliviermarti trying to understand why a time series based on data using a noleap calendar was plotted (seemingly) correctly with default settings, but was shifted (30 years in our case) when we tried to format the tick labels with set_major_formatter, following the appropriate examples in the matplotlib gallery. We were lucky to spot this, because matplotlib was not generating any error! I guess matplotlib was happy enough to handle cftime data as if it was regular datetime data

The question now is how to tell our climate data users that they (or most likely their unsuspecting interns) will get horribly wrong plots if they rely on matplolib defaults...

What could work would be to display side by side a matplotlib plot using some dummy data with a cftime+noleap time axis, and a correct plot using nc-time-axis, if somebody can come up with a simple example (I'm not volunteering!)

@jypeter jypeter added New: Documentation Highlight a new community raised "documentation" issue Type: Documentation labels Jan 11, 2023
@rcomer
Copy link
Member

rcomer commented Jan 12, 2023

Related: matplotlib/matplotlib#24951

@spencerkclark
Copy link
Member

Thanks for raising this @jypeter -- sorry this tripped you and @oliviermarti up! I'm optimistic there might something that could be done in matplotlib to address this (i.e. it would be great if matplotlib could raise an error for an unrecognized date type rather than display erroneous values), so we'll see what happens there.

@jypeter
Copy link
Author

jypeter commented Jan 12, 2023

Well, it's certainly not nc-time-axis' fault!

We don't know how long it will take for a fix to be added to matplotlib, and then when we will use this updated matplotlib in our environments, so an example of what happens when people don't use nc-time-axis would be very useful

Anyway, I think examples of what can silently go dreadfully wrong are very good teaching examples, and we have to remind our students (and not just them) to pay attention to their code and the resulting output!

Just a few days ago, some of our students were talking about how neat this hyped chatgpt thingy was for generating code. I don't want them to go this way... :-(

We have here an opportunity to kill several birdsbugs with one stone:

  • avoid calendar-related display bugs
  • remind people to check simple things in their plot (like is what is displayed on an axis consistent with the data?)
  • advertise nc-time-axis

@rcomer
Copy link
Member

rcomer commented Jan 12, 2023

I may have misunderstood but, from the discussion at Unidata/cftime#303, it looks like you didn't know to use nc-time-axis. If a user does not know to use this package, then they wouldn't look in this package's docs for how not to do it.

@jypeter
Copy link
Author

jypeter commented Jan 12, 2023

You are right, most people unfortunately don't know about nc-time-axis (and possible non-standard calendars related problems)!

It took @oliviermarti and I some time to identify the problem and try to find a(n existing) fix. Finding the package with Google can be done, but we would like to warn our lab users (and the IPSL modellers) and tell them how to fix the problem

I think the best way to do it would be to send a link to an example in nc-time-axis documentation (with simple dummy data using non-standard calendars) showing them what happens when they plot data with/without nc-time-axis (and with/without a date formatter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New: Documentation Highlight a new community raised "documentation" issue Type: Documentation
Projects
Status: No status
Development

No branches or pull requests

3 participants