Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix multiple zero labels when using SymLogNorm#10129

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

Raab70
Copy link
Contributor

@Raab70Raab70 commentedDec 29, 2017
edited
Loading

PR Summary

Use the previously unused position of a tick label to ensure that only a single zero label is rendered when using SymLogNorm. I store the first time a zero label is encountered and return blanks for all following zeros. The documentation on theticker.SymmetricalLogLocator.tick_values shows how these multiple zeros come to be through the linear approximation near zero.

As per discussion below I have taken a different approach, trying to fix the root cause of the problem in the locator (ticker.SymmetricalLogLocator.tick_values) so that the extra zero ticks are never created in the first place.

Fixes#10122

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • N/A New features are documented, with examples if plot related
  • N/A Documentation is sphinx and numpydoc compliant
  • N/A Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • N/A Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

tillahoffmann reacted with hooray emoji
Copy link
Member

@jklymakjklymak left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems OK to me. But isn't the root problem that there are two zeros returned by the Locator? Can't we just remove the duplicate entry from the Locator?

@jklymak
Copy link
Member

classSymmetricalLogLocator(Locator):

returnself.raise_if_exceeds(np.array(ticklocs))

anntzer
anntzer previously requested changesDec 29, 2017
Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The strategy of this PR can't work. If you run e.g. examples/pyplots/pyplot_scales.py with this PR applied, and move or zoom the symlog axes, the label at 0 disappears (because it is never redrawn).

I believe that@jklymak's idea is the correct approach.

@Raab70
Copy link
ContributorAuthor

Raab70 commentedDec 29, 2017 via email

That’s a great point. I’ll spend some more time in the locator and the linear approximation around zero and see if there’s a good way to ensure only a single zero value.
On Dec 29, 2017, 2:14 PM -0600, Antony Lee ***@***.***>, wrote:@anntzer requested changes on this pull request. The strategy of this PR can't work. If you run e.g. examples/pyplots/pyplot_scales.py with this PR applied, and move or zoom the symlog axes, the label at 0 disappears (because it is never redrawn). I believe that@jklymak's idea is the correct approach. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

@tacaswelltacaswell added this to thev2.2 milestoneDec 30, 2017
@Raab70Raab70force-pushed thebug-fix/logsymnorm-zero-labels branch fromfd130c1 tob26b598CompareDecember 30, 2017 15:22
@Raab70Raab70force-pushed thebug-fix/logsymnorm-zero-labels branch fromb26b598 to7fe5e4eCompareDecember 30, 2017 15:27
@Raab70
Copy link
ContributorAuthor

@jklymak@anntzer Thanks for your help and patience, I believe this is the root of the issue. The multiple zeros are stemming from subticks being added. This change just prevents the addition of subticks to the zero label (since they will all be zero).

@tacaswell
Copy link
Member

👍 That makes sense and looks like a reasonable fix.

Could you add a test? I suspect creating a symlog axis and then asserting that there is only 0 zero label it in is the best approach (no need for an image test). The OP example is maybe a bit complex to trigger this, but as a last resort would be ok to use a test.

tacaswell
tacaswell previously requested changesJan 2, 2018
Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fix looks good, just needs a test.

Anyone can dismiss this when a test is added.

@anntzeranntzer dismissed theirstale reviewJanuary 2, 2018 00:42

implementation changed

@jklymakjklymak dismissedtacaswell’sstale reviewJanuary 2, 2018 17:26

Dismissing@tacaswell review as test now added per his wishes

@jklymak
Copy link
Member

Just for completeness, the test is:

frommatplotlibimportpyplotaspltimportmatplotlibasmplfig,axes=plt.subplots(1,2,True,True)fori,axinenumerate(axes):im=ax.imshow([[0]],norm=mpl.colors.SymLogNorm(1e-5,vmin=-1,vmax=1))cb=plt.colorbar(im,ax=ax)# Clean up the labelszero_labelled=Falseforlabelincb.ax.yaxis.get_ticklabels():iflabel.get_text()==r'$\mathdefault{0}$':ifzero_labelled:label.set_visible(False)zero_labelled=Trueplt.show()

@dstansby
Copy link
Member

Thanks a lot@Raab70!

@dstansbydstansby merged commita1e9db1 intomatplotlib:masterJan 4, 2018
@Raab70Raab70 deleted the bug-fix/logsymnorm-zero-labels branchJanuary 4, 2018 20:09
@QuLogicQuLogic modified the milestones:needs sorting,v2.2.0Feb 12, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

@dstansbydstansbydstansby approved these changes

@tacaswelltacaswelltacaswell left review comments

@anntzeranntzeranntzer left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.2.0
Development

Successfully merging this pull request may close these issues.

Color bar has multiple labels for 0 if matplotlib.colors.SymLogNorm is used
6 participants
@Raab70@jklymak@tacaswell@dstansby@anntzer@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp