Skip to content

Conversation

@spencerkclark
Copy link
Member

@spencerkclark spencerkclark commented Aug 15, 2021

🚀 Pull Request

This implements the proposal outlined in #41 (comment).

Description

The following example now works. Here I am setting a single tick on the x-axis and labeling it with a date format of "%Y-%m" using the newly added CFTimeFormatter:

import random

import cftime
import matplotlib.pyplot as plt
import nc_time_axis

dt = [cftime.DatetimeNoLeap(2017, 2, day, calendar="noleap") for day in range(1, 28)]
temperatures = [round(random.uniform(0, 12), 3) for _ in range(len(dt))]

fig, ax = plt.subplots(1, 1)
ax.plot(dt, temperatures)
ax.set_xticks([cftime.DatetimeNoLeap(2017, 2, 10)])
ax.xaxis.set_major_formatter(nc_time_axis.CFTimeFormatter("%Y-%m", "noleap"))

example-xticks

The NetCDFTimeDateFormatter has been renamed to AutoCFTimeFormatter. For backwards compatibility, using the name NetCDFTimeDateFormatter will still work, but will raise a FutureWarning.

@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2021

Codecov Report

Merging #84 (2c8a84a) into main (ad91535) will increase coverage by 3.60%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
+ Coverage   90.69%   94.30%   +3.60%     
==========================================
  Files           1        1              
  Lines         172      193      +21     
  Branches       42       44       +2     
==========================================
+ Hits          156      182      +26     
+ Misses         11        6       -5     
  Partials        5        5              
Impacted Files Coverage Δ
nc_time_axis/__init__.py 94.30% <100.00%> (+3.60%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad91535...2c8a84a. Read the comment docs.

@spencerkclark spencerkclark marked this pull request as ready for review August 16, 2021 10:58
Copy link
Contributor

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

I like this change!
Do I understand that the behaviour is unchanged for almost all cases?

@spencerkclark
Copy link
Member Author

That's correct. All the default behavior should be identical to before. The behavior only changes after someone calls set_xticks or set_yticks; instead of erroring we now use a default format and this format can be overridden using the newly added CFTimeFormatter.

@spencerkclark spencerkclark merged commit 837fec3 into SciTools:main Aug 17, 2021
@spencerkclark spencerkclark deleted the fix-xticks branch August 17, 2021 15:36
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.

3 participants