Skip to content

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

Merged
merged 1 commit into from
Feb 6, 2017

Conversation

madphysicist
Copy link
Contributor

@madphysicist madphysicist commented Jan 27, 2017

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.

@madphysicist
Copy link
Contributor Author

@story645: given your concern with PercentFormatter, I think you might be a good person to have reviewing this.


def convert_to_pct(self, x):
return 100.0 * (x / self.xmax)

def get_symbol(self):
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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))
Copy link
Member

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.

@@ -536,12 +536,66 @@ def test_formatstrformatter():


@pytest.mark.parametrize('xmax, decimals, symbol, x, display_range, expected',
percentformatter_test_cases)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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))
Copy link
Member

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

Copy link
Contributor Author

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

@@ -536,12 +536,66 @@ def test_formatstrformatter():


@pytest.mark.parametrize('xmax, decimals, symbol, x, display_range, expected',
percentformatter_test_cases)
Copy link
Member

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?

@madphysicist
Copy link
Contributor Author

madphysicist commented Jan 30, 2017

I have responded to all the review comments. The lists of test parameters was made into separate references in #7993.

@madphysicist
Copy link
Contributor Author

I am pretty sure that the Appveyor failure is not something I did, but I could be very wrong about that.

@story645
Copy link
Member

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.

@madphysicist
Copy link
Contributor Author

Well, #7528 started getting the same error after I rebased, so I am pretty sure it's something on master. Blame says @QuLogic is the last person to modify that particular test about 10 days ago, but it may not be the test itself that is causing the failure.

@madphysicist madphysicist force-pushed the pct-formatter-updates branch 2 times, most recently from 217536d to c33266b Compare January 30, 2017 20:35
@story645 story645 changed the title ENH: Fixed PercentFormatter usage with latex [MRG+1] ENH: Fixed PercentFormatter usage with latex Jan 31, 2017
@@ -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))
Copy link
Member

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.

@@ -511,35 +511,66 @@ def test_formatstrformatter():
assert '002-01' == tmp_form(2, 1)


percentformatter_test_cases = (
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

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.

@madphysicist madphysicist force-pushed the pct-formatter-updates branch from c33266b to fde20d2 Compare February 1, 2017 02:56
@madphysicist
Copy link
Contributor Author

@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?

@madphysicist
Copy link
Contributor Author

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.

@madphysicist
Copy link
Contributor Author

I suspect that the break may not be related to my tests...

@madphysicist
Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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)

@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):
Copy link
Member

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
@madphysicist madphysicist force-pushed the pct-formatter-updates branch from 43a6bd6 to 6add6ce Compare February 6, 2017 16:53
@QuLogic QuLogic changed the title [MRG+1] ENH: Fixed PercentFormatter usage with latex ENH: Fixed PercentFormatter usage with latex Feb 6, 2017
@QuLogic QuLogic merged commit 91261e7 into matplotlib:master Feb 6, 2017
@QuLogic QuLogic added this to the 2.1 (next point release) milestone Feb 6, 2017
@madphysicist madphysicist deleted the pct-formatter-updates branch February 7, 2017 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants