-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Fixed PercentFormatter usage with latex #7965
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
@story645: given your concern with |
lib/matplotlib/ticker.py
Outdated
|
||
def convert_to_pct(self, x): | ||
return 100.0 * (x / self.xmax) | ||
|
||
def get_symbol(self): |
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.
Can you make this function private? If possible, we try to avoid adding more elements to the public API that aren't absolutely necessary.
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.
How about making self.symbol
into a property since it's already public and removing the need for this method entirely?
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.
sounds good.
@@ -22,7 +22,7 @@ def setup(ax): | |||
|
|||
|
|||
plt.figure(figsize=(8, 5)) |
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.
Figure should be made a little bigger to fit the new Axes.
lib/matplotlib/tests/test_ticker.py
Outdated
@@ -536,12 +536,66 @@ def test_formatstrformatter(): | |||
|
|||
|
|||
@pytest.mark.parametrize('xmax, decimals, symbol, x, display_range, expected', | |||
percentformatter_test_cases) |
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.
Why move this down but not delete percentformatter_test_cases
?
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.
Accidentally copied instead of cutting, then forgot because the tests passed. Will fix.
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.
same comment as on other PR, maybe keep the testcase and id outside of the decorator and just refer to 'em?
# Set the formatter | ||
plt.gca().yaxis.set_major_formatter(formatter) | ||
plt.gca().yaxis.set_major_formatter(PercentFormatter(xmax=1)) |
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.
I know this is beyond the scope of this doc, but is there anyway to do this same thing without a plt.gca().yaxis
? Also comment should possibly explain what xmax means here
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 is not out of scope at all if you are OK with an extra call to plt.subplots()
.
lib/matplotlib/tests/test_ticker.py
Outdated
@@ -536,12 +536,66 @@ def test_formatstrformatter(): | |||
|
|||
|
|||
@pytest.mark.parametrize('xmax, decimals, symbol, x, display_range, expected', | |||
percentformatter_test_cases) |
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.
same comment as on other PR, maybe keep the testcase and id outside of the decorator and just refer to 'em?
I have responded to all the review comments. The lists of test parameters was made into separate references in #7993. |
I am pretty sure that the Appveyor failure is not something I did, but I could be very wrong about that. |
You could click through and see if the error has anything to do with you, but travis and appveyor have also been messed around with a lot lately. |
217536d
to
c33266b
Compare
@@ -21,8 +21,8 @@ def setup(ax): | |||
ax.patch.set_alpha(0.0) | |||
|
|||
|
|||
plt.figure(figsize=(8, 5)) | |||
n = 6 | |||
plt.figure(figsize=(9, 5)) |
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.
You've changed the width, not the height.
lib/matplotlib/tests/test_ticker.py
Outdated
@@ -511,35 +511,66 @@ def test_formatstrformatter(): | |||
assert '002-01' == tmp_form(2, 1) | |||
|
|||
|
|||
percentformatter_test_cases = ( |
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.
I thought @story645 suggested keeping this.
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.
Got sorted out in #7993
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.
They'll conflict then; which should be merged first?
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.
#7993 please. I'd like to rebase all my open PRs onto it. It's ready to go, just waiting for Mac test to run.
c33266b
to
fde20d2
Compare
@QuLogic. I fixed the size issue. In addition to #7993, the order of this PR with respect to #7482 matters as well since they both add examples to the big formatter demo. I updated the same resizing issue in #7482 as well. #7482 should come after this PR. Just out of curiosity, is there some mechanism in GitHub for specifying the order in which PRs should be merged? |
9f1aaed
to
98211e4
Compare
98211e4
to
43a6bd6
Compare
Fixed PEP8 errors, should be ready to merge when tests are done. This PR needs to come before #7482 because of the conflicts between them. |
I suspect that the break may not be related to my tests... |
ready to merge with one more approval. |
# default labels by 100, making them all percentages | ||
formatter = FuncFormatter(to_percent) | ||
# Make a normed histogram. It'll be multiplied by 100 later. | ||
plt.hist(x, bins=50, normed=True, axes=ax) |
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.
Doesn't ax.hist
work here?
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.
it's a pylab example so I think it has to be plt.hist
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.
@madphysicist already changed it to fig, ax
, so I don't see why.
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.
Technically, plt.*
is already not pylab, so I will go ahead and make the change. I am pretty sure that there are plenty of pylab examples that demo the OO API.
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.
I agree @madphysicist a good deal of time was spent removing the use of pylab from all the examples last year. In my opinion most of the pylab examples should be moved to other folders with more meaningful names as they are cleaned up and improved (But I am out of touch on what the current plan is for restructuring the examples)
lib/matplotlib/tests/test_ticker.py
Outdated
@pytest.mark.parametrize( | ||
'xmax, decimals, symbol, x, display_range, expected', | ||
percent_data, ids=percent_ids) | ||
def test_percentformatter(self, xmax, decimals, symbol, | ||
def test_basic(self, xmax, decimals, symbol, | ||
x, display_range, expected): |
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.
Not aligned any more.
Added an example to the big formatter example Added test for latex correctness Modified existing pylab example
43a6bd6
to
6add6ce
Compare
This PR addresses a nagging issue that I have had with PercentFormatter, namely that it does not handle LaTeX labels correctly unless preconfigured to do so. The proposed solution allows the labels to be generated correctly with the same formatter even if
rcParams['text.usetex']
changes between calls.I also added it to the big formatter example and modified one of the existing pylab examples where it clearly belongs.
This PR also includes the of IDs to
test_percentformatter
that I made in #7482.