ENH: Added a PercentFormatter class to matplotlib.ticker#6251
ENH: Added a PercentFormatter class to matplotlib.ticker#6251efiring merged 1 commit intomatplotlib:masterfrom
PercentFormatter class to matplotlib.ticker#6251Conversation
|
@mdboom While I realize that you have a script to do this, it is really disconcerting to see your name pop up fractions of a second after I create a PR :) |
lib/matplotlib/ticker.py
Outdated
| suitable for use with single-letter representations of powers of | ||
| 1000. For example, 'Hz' or 'm'. | ||
|
|
||
| `places` is the percision with which to display the number, |
|
I am not familiar enough with Python 2.7 to immediately understand why the following is not working: Are nested formats not allowed? |
lib/matplotlib/ticker.py
Outdated
| already scaled to be percentages, `mx` will be 100. Another common | ||
| situation is where `max` is 1.0. | ||
| """ | ||
| def __init__(self, mx=100, decimals=None, symbol='%'): |
There was a problem hiding this comment.
I think people will rarely want to specify max, so I would put it after the decimals kwarg.
There was a problem hiding this comment.
I disagree. The most common parameter to modify would be max. This is intended for data going from 0 to 1, or as in the case of the SO question, from 0 to 5. I would expect the decimals argument to generally remain None assuming I have done a decent job with the automated version.
|
There are so many cleanup changes here that I recommend breaking this into two PRs: one for the cleanups, and a second one for the new feature. |
|
No problem with that. Is there an easy way to do that without closing this PR? |
lib/matplotlib/ticker.py
Outdated
| 1000. For example, 'Hz' or 'm'. | ||
|
|
||
| `places` is the percision with which to display the number, | ||
| `places` is the prrcision with which to display the number, |
That's https://waffle.io/
Create a new branch starting on this one, rebase it to include only cleanup, and open a new PR for it. When that's merged, rebase this one on top of master and drop all the cleanup from here. |
|
I think you would make a separate branch on your repo for the cleanups, and make a PR from that. Then, on your pctFormatter branch, isolate the PercentFormatter part with additional commits, and use 'git rebase -i' to squash it down to a single commit. Force-push that to your github repo, and it will replace the present commits in the present PR. |
3318d77 to
06d6f41
Compare
|
I did the split (#6253) and fixed the Py2.7 error. Turns out Py3 automatically converts acceptable format precisions into an int. Py2 does not. The only potentially unrelated change I kept here was moving |
matplotlib.tickermatplotlib.ticker
matplotlib.tickerPercentFormatter class to matplotlib.ticker
94a8859 to
fbb8eb4
Compare
|
Metabolized the docs of |
c91a87b to
f123047
Compare
|
I think that this PR is complete (ready for further review). Same goes for #6253. The failure in Appveyor is the sporadic image comparison failure. It is not related to the code I added as far as I can tell. |
|
Squawk. |
|
Cc: @efiring. |
|
In reading the new code, I find that I waste a lot of time trying to figure out what |
f123047 to
5161407
Compare
|
I changed On a side-note, I got |
lib/matplotlib/tests/test_ticker.py
Outdated
| (42, None, '^^Foobar$$', 21, 12, '50.0^^Foobar$$'), | ||
| ) | ||
| for xmax, decimals, symbol, x, display_range, expected in test_cases: | ||
| yield _percent_format_helper, xmax, decimals, symbol, x, display_range, expected |
There was a problem hiding this comment.
pep-8 failure here: line too long. You could use parentheses; or you could use
for case in test_cases:
yield (_percent_format_helper,) + caseI haven't tested, but I think that would work and would be more readable.
Maybe I would use args and test_args instead of case and test_cases.
|
In addition to the pep-8 failure noted above there is a real failure that I have not tracked down (probably you will spot it instantly). Once those are taken care of, I think this will be functionally ready. It's a nice contribution. You could neaten it up by rebasing to squash the commits. |
|
I went with and also fixed the other stupid typo. Will push with squash soon. |
27cf9a5 to
02f61c0
Compare
|
And now I know why I should have listened the first time. |
02f61c0 to
0e35e6b
Compare
|
I don't think the Travis failure is related to my code. |
|
Thank you, @madphysicist! |
|
No problem. Thanks for looking over and accepting my PR! |
This is suitable for formatting axes labels as percentages. It has some nice features like being able to convert from arbitrary data scales to percents, a customizable percent symbol and either automatic or manual control over the decimal points.
The original motivation came from my own work as well as these two Stack Overflow questions: