-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Automatically create tick formatters for str and callable inputs. #16715
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
Conversation
3744780
to
135fb1c
Compare
@tacaswell @story645 Great, thank you! I don't know why the test coverage has dropped, I added new tests that, as far as I can tell, cover the new code paths. Assuming this is a good approach, the big outstanding issue in my mind is whether this should be used more in the documentation. There are several examples using the old-style |
51d0d1d
to
e07c5df
Compare
@toddrjen can you please provide some examples here cause I'm struggling a bit in finding 'em in the PR |
@story645 One example for the axs[5].xaxis.set_major_formatter('{x} km') Which would replace: from matplotlib import ticker
axs[5].xaxis.set_major_formatter(ticker.StrMethodFormatter('{x} km')) One for the function approach used in the documentation: axs[3].xaxis.set_major_formatter(lambda x, pos: str(x-5)) Which would replace: from matplotlib import ticker
axs[3].xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: str(x-5))) |
In the pr it’s not clear that you need a pos argument to your function or why. |
@jklymak Where, exactly, do you think this should be mentioned? Can you comment on the specific lines or blocks where you think this should be changed? In most cases I am just using or following up on the existing description for the |
It needs to be documented somewhere, otherwise how are people to know what a valid callable is? |
@jklymak Please see the updated version. I have added more explicit documentation. |
79b548b
to
43b395c
Compare
I have added a new commit where I modified a bunch of existing examples and tutorials, and the previous documentation, to make better use of the new syntax. These changes may be more controversial so I added them to a separate commit so they would be easier to roll back. Please take a look and see what you think. I don't know why the tests are failing. It doesn't appear to be related to my commit but I am not sure. |
34030d3
to
e04d08a
Compare
@story645 All tests are passing now. Is there anything else I need to do or is this ready? |
Sorry I still owe you feedback on this, just wanted to note that I'm +1 on this idea since learning that spotify is basically using this sort of thing as their motivating example for writing a new charting library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot of especially the language changes are more suggestions than must changes, but I really want the test cases to be broken up
bd151ee
to
642928d
Compare
@story645 All the discussed changes should be implemented. Please take a look. I am still waiting on feedback on a few issues. |
As stated above I'm basically fine with the PR, but don't like one very specific point (direct support for strings) so don't particularly want to approve it with that feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems good, and I think will help 99% of folks who don't want to learn the arcana of Formatters. Do we want to replace every instance of StrMethodFormatter
and FuncFormatter
by this idiom? There is some advantage to pointing out the ticker module and the existence of the suite of Formatters.
I didn't replace every instance. |
Hi Todd, thanks for hanging in there! We're aiming to get this into 3.3 (rc out in a week or so). Giving it some more thought, keeping the current formatter signature seems fine as it's consistent with the docs and what folks will find on stackoverflows. Can revisit in a later PR. Do you feel it's ready to merge or do you have any additions to make? |
Also now thinking the arguments fix should actually be on FuncFormatter since it's not clear why it needs two https://matplotlib.org/_modules/matplotlib/ticker.html#FuncFormatter |
@story645 If all the tests pass I think it is ready to merge. |
PR Summary
This allows
matplotlib.axis.Axis.set_major_formatter
andmatplotlib.axis.Axis.set_minor_formatter
to accept astr
or function (really anycallable
) in addition to amatplotlib.ticker.Formatter
. This will create and use amatplotlib.ticker.StrMethodFormatter
andmatplotlib.ticker.FuncFormatter
, respectively. This significantly reduces the barrier to using custom formatters in simple cases.This was previously discussed on the matplotlib-devel mailing list.
PR Checklist