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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickplot Automatic Time Axis Label Completely Incorrect #5426

Closed
rebeccaherman1 opened this issue Aug 17, 2023 · 2 comments 路 Fixed by #5561
Closed

Quickplot Automatic Time Axis Label Completely Incorrect #5426

rebeccaherman1 opened this issue Aug 17, 2023 · 2 comments 路 Fixed by #5561
Assignees

Comments

@rebeccaherman1
Copy link

馃悰 Bug Report

The automatic quickplot time label is unrelated to the printed time ticks and even to native cube units

Minimum Reproducible Code

Any spatio-temporal cube will do; I've saved an example of Pacific SST from a pre-Industrial control run using years 1191-1200, attached it below (be sure to remove .txt from the name):
sst_example.nc.txt

import iris
import iris.quickplot as qplt
import esmvalcore.preprocessor as pp
ex = iris.load_cube('sst_example.nc')  
m_ex = pp.meridional_statistics(ex, operator='mean')
qplt.pcolormesh(m_ex)
#prints native units of cube
Time = m_ex.coord('time')
time_meta_data = Time.metadata.units
Calendar = time_meta_data.calendar
U = time_meta_data.cftime_unit
print(U)
print(max(Time.points))

Expected behaviour

The native units of the cube m_ex are days since 1850-1-1 00:00:00 (see printed output in the screenshot below), and the values are incredibly large negative numbers (the largest time value is -237266.5). However, I do not expect to see tick labels in days relative to some offset, but in absolute time presented in years, ranging from 1191 to 1200. I thus expect the time axis to be labelled Year, or Time / Year

Observed behavior

The time ticks appear as expected, as all are between 1191 and 1200. However, the automatic label says Time / days since 1970-01-01. This is clearly not consistent with the time ticks because the presented numbers of in units of years with no time offset. Furthermore, t's completely unclear where the offset in the label came from, since the native offset of the cube being plotted (m_ex) is 1850. I wonder if these units have been hard-coded somewhere?

Screenshot from 2023-08-17 15-44-11

@rcomer
Copy link
Member

rcomer commented Aug 17, 2023

You are right. It is hard-coded here:

elif units.is_time_reference():
# iris.plot uses matplotlib.dates.date2num, which is fixed to the below unit.
if version.parse(_mpl_version) >= version.parse("3.3"):
days_since = "1970-01-01"
else:
days_since = "0001-01-01"
units = "days since {}".format(days_since)

and I agree that specifying the units like this is misleading. Note that if you zoom in enough on your plot, you will no longer see years but Matplotlib automatically starts showing the dates in YYYY-MM-DD format. I do not think there is an easy way to make the label reflect that. So maybe it would be best to just not specify a unit here, which is what happens if you make a line plot rather than a pcolormesh:

import iris
import iris.quickplot as qplt

cube = iris.load_cube("sst_example.nc")
qplt.plot(cube[:, 0, 0])

image

@rcomer
Copy link
Member

rcomer commented Aug 17, 2023

#616 removed the unit for the 1D plots. I guess something else developed in the meantime to make the 2D plot ticks use Matplotlib鈥檚 date formatter, but the label has not been updated to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants