Skip to content

DOC: Add Date Tick Locators and Formatters example #21874

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

Merged
merged 1 commit into from
Dec 7, 2021

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Dec 6, 2021

PR Summary

Add Date Tick Locators and Formatters example. Closes #17283.

I noticed that

class rrulewrapper:
def __init__(self, freq, tzinfo=None, **kwargs):
has no docstring and hence can't be referred to in the documentation (see admonition:: References; the same pertains to
* `RRuleLocator`: Locate using a `matplotlib.dates.rrulewrapper`.
).

grafik


grafik

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@jklymak jklymak added this to the v3.6.0 milestone Dec 6, 2021
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

This looks great! Using eval() seems a bit odd to me - is there a reason that locators and formatters can't contain the actual locator/formatter instances instead of their eval strings?

@StefRe
Copy link
Contributor Author

StefRe commented Dec 7, 2021

@dstansby the eval is just to prevent redundant definition of the string 'AutoDateLocator(maxticks=8)' and the locator itself, i.e. it's meant as a shortcut of writing e.g.

locators = [
    ('AutoDateLocator(maxticks=8)', AutoDateLocator(maxticks=8), '2003-02-01', '%Y-%m'),
    ...

Maybe using eval is not really best practice but it reduces the possibility of mistakes/inconsistencies between the code and the text in this case.

@jklymak
Copy link
Member

jklymak commented Dec 7, 2021

I guess I but the argument that the eval is useful here...

@story645
Copy link
Member

story645 commented Dec 7, 2021

Maybe using eval is not really best practice but it reduces the possibility of mistakes/inconsistencies between the code and the text in this case.

Would a repr on the objects (assuming it exists) print anything different from the eval?

@StefRe
Copy link
Contributor Author

StefRe commented Dec 7, 2021

@story645 repr(AutoDateLocator(maxticks=8)) gives '<matplotlib.dates.AutoDateLocator object at 0x000001CE4F687CA0>'.

Defining nice reprs wouldn't be enough, however, as we also need the arguments of the function calls.

@story645
Copy link
Member

story645 commented Dec 7, 2021

Defining nice reprs wouldn't be enough, however, as we also need the arguments of the function calls.

Why couldn't those be in the repr?

@StefRe
Copy link
Contributor Author

StefRe commented Dec 7, 2021

@story645
I only have very basic knowledge of python in this respect, maybe I'm completely wrong:

When I try AutoDateLocator.__repr__ = lambda self: f'AutodateLocator(maxticks={self.maxticks})' then repr(AutoDateLocator(maxticks=8)) returns 'AutodateLocator(maxticks={0: 8, 1: 8, 3: 8, 4: 8, 5: 8, 6: 8, 7: 8})', i.e. the class variable maxticks. I don't know how to get the value passed in during the function call. But even if this is possible, I find defining all the repr rather verbose and a bit hacky as compared to a simple eval.

@dstansby
Copy link
Member

dstansby commented Dec 7, 2021

In an ideal world we would define sensible __repr__s on each of the locators/formatters so they could be used - I think that's a stretch goal, and this PR is worth considering regardless of that.

@jklymak jklymak merged commit fb5b91e into matplotlib:main Dec 7, 2021
@jklymak
Copy link
Member

jklymak commented Dec 7, 2021

Thanks @StefRe for your very helpful contributions!

@StefRe StefRe deleted the date_fmt-loc_reference branch December 8, 2021 07:17
@StefRe
Copy link
Contributor Author

StefRe commented Dec 8, 2021

@jklymak Thanks!
What about the rrulewrapper issue I mentioned at the very beginning? Open a new issue for this? Should I (for the time being) remove the reference to rrulewrapper as there's no link:
grafik

@jklymak
Copy link
Member

jklymak commented Dec 8, 2021

Sure, open an issue. Seems the solution is to add a docstring to rrulewrapper if it is public API...

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

Successfully merging this pull request may close these issues.

Create Date Formatter/Locator Reference
4 participants