Skip to content

Date Tick Labels example #19203

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

Closed
rcomer opened this issue Dec 30, 2020 · 4 comments
Closed

Date Tick Labels example #19203

rcomer opened this issue Dec 30, 2020 · 4 comments
Milestone

Comments

@rcomer
Copy link
Member

rcomer commented Dec 30, 2020

Problem

The Date Tick Labels example has a couple of lines whose purpose are unclear, and I'm actually not sure whether they are achieving anything:

# Format the coords message box
ax.format_xdata = mdates.DateFormatter('%Y-%m')
ax.format_ydata = lambda x: '$%1.2f' % x # format the price.

I don't know what the "coords message box" referred to in the comment is. I tried commenting out the two ax.format_?data lines, and the output plot seemed to be the same.

Suggested Improvement

It looks like these lines have been there for a very long time so possibly they no longer do what they were originally written to do. In which case they could just be removed. It seems plausible that the intent of line 60 is to format the y-axis, so possibly that could be replaced with something like

ax.yaxis.set_major_formatter(lambda x, pos: f'${x:.2f}')  # format the price.

If these lines are still doing something useful, then more information in that comment on line 58 would be really helpful.

@jklymak
Copy link
Member

jklymak commented Dec 30, 2020

I suppose this could be a little more verbose, but this formats the numbers displayed as the pointer moves through the axes. Of course you won't see this if you don't use an interactive backend.

@rcomer
Copy link
Member Author

rcomer commented Dec 30, 2020

Thanks @jklymak. I was using an interactive backend, but it had not occurred to me to wave my cursor over the plot! This is functionality that I had no idea existed.

@rcomer
Copy link
Member Author

rcomer commented Dec 30, 2020

I have opened #19204 to expand that comment.

@tacaswell
Copy link
Member

Closed by #19204

@tacaswell tacaswell added this to the v3.4.0 milestone Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants