Skip to content

DOC: Update and consolidate Custom Tick Formatter for Time Series example #21873

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 2 commits into from
Jan 5, 2022

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Dec 6, 2021

PR Summary

See #17283 (comment):

  • consolidate with Date Index Formatter example and move to Ticks section
  • use smaller date range to better show the difference to index plotting
  • visualize missing date section
  • update sample data description
  • fix index formatter (empty labels instead of repeated first/last label for out-of-range data)
  • Fix goog.npz sample data description

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).

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

If you move something, please use the redirect-from directive to indicate where it went, that way old links don't break.

@StefRe
Copy link
Contributor Author

StefRe commented Dec 6, 2021

@jklymak Sorry to bother you with that but I can't get the redirect working. I now added the redirect-from directives like that (didn't push it yet):

"""
=====================================
Custom tick formatter for time series
=====================================

.. redirect-from:: /gallery/text_labels_and_annotations/date_index_formatter
.. redirect-from:: /gallery/ticks/date_index_formatter2
  

According to the documentation this should yield the files build/doc/html/gallery/text_labels_and_annotations/date_index_formatter.html and build/doc/html/gallery/ticks/date_index_formatter2.html but they aren't there (make html finished with no errors or warnings).

I cross-checked with other examples and they don't seem to work either. For instance

.. redirect-from:: /tutorials/basic/sample_plots
should generate build/doc/html/tutorials/basic/sample_plots.html but it doesn't exist.
Obviously I don't correctly understand the documentation on redirects, so maybe you could lend me a helping hand.

@jklymak
Copy link
Member

jklymak commented Dec 6, 2021

Perhaps it is broken?

@StefRe StefRe force-pushed the date_index_formatter branch from fe0320d to c7bf99d Compare December 6, 2021 15:19
@StefRe
Copy link
Contributor Author

StefRe commented Dec 6, 2021

Hm, so I just pushed the changes with the redirec-from directives although they don't seem to work as I take from your answer that I've used them corretly.

Comment on lines +56 to +60
# Create an index plot (x defaults to range(len(y)) if omitted)
ax2.plot(r.adj_close, 'o-')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just be explicit rather than make the user go back and parse the comment?

Suggested change
# Create an index plot (x defaults to range(len(y)) if omitted)
ax2.plot(r.adj_close, 'o-')
# Create an index plot:
ax2.plot(np.arange(0, len(r.adj_close)), r.adj_close, 'o-')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this change on purpose to underline/explain that this is an index plot which by definition plots the values versus an index number. In my view, the plot command is more legible/clearer without the range definition as the first argument. Besides, this kind of plot is explicitly advertised in plot, so I'd rather keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

I think, however, that most of the core devs consider this a nasty holdover from the Matlab days, and prefer the more explicit interface. Certainly when I was reading this I was confused about what r.adj_close was, and how it was plotting x and y, and then I had to go up, figure out what r.adj_close was and then figure out why it didn't need two arguments.

In general, I wonder if it is more confusing than not to keep r as a structured array? How common do we think those are in the wild (I never use them, but then I use xarray all the time).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

most of the core devs consider this a nasty holdover from the Matlab days, and prefer the more explicit interface

hm, I find this feature quite handy, but if this usage is not recommended it should be described as discouraged in the docs, shouldn't it

I wonder if it is more confusing than not to keep r as a structured array

Alternatives (pandas, xarray, ...) require additional dependencies, csv requires additional date conversion, so why not leave it as a structured array (given that the data structure is described in detail in the comment at lines 24-27)?

@jklymak jklymak added this to the v3.6.0 milestone Jan 5, 2022
StefRe added 2 commits January 5, 2022 14:52
- consolidate with Date Index Formatter example and move to Ticks
  section
- use smaller date range to better show the difference to index plotting
- visualize missing date section
- update sample data description
- fix index formatter (empty labels instead of repeated first/last
  label for out-of-range data)
@StefRe StefRe force-pushed the date_index_formatter branch from c7bf99d to 5ad9546 Compare January 5, 2022 13:53
@jklymak
Copy link
Member

jklymak commented Jan 5, 2022

Lets merge as an improvement.

@jklymak jklymak merged commit 1a3be58 into matplotlib:main Jan 5, 2022
@StefRe
Copy link
Contributor Author

StefRe commented Jan 5, 2022

@jklymak Thanks for all your patience with me 👍.

@StefRe StefRe deleted the date_index_formatter branch January 5, 2022 15:48
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.

2 participants