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

Let Formatters format all ticks at once.#12909

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
efiring merged 3 commits intomatplotlib:masterfromanntzer:format_ticks
Jan 29, 2019

Conversation

anntzer
Copy link
Contributor

This is useful especially when labels are interdependent (e.g.
ConciseDateFormatter, but also LogFormatter which currently relies on
set_locs, etc.). xref#10841, maybe of interest for@jklymak.

Becauseset_major_formatter/set_minor_formatter (somewhat unusually)
enforces that its argument is a Formatter subclass, even third-party
formatters will inherit from the base class and have this method
defined.

PR Summary

PR Checklist

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

@jklymak
Copy link
Member

jklymak commentedNov 30, 2018
edited
Loading

I like this and agree it makes a lot more sense, but...

If someone callsformatter() for some reason (old custom axis of some sort?) it still needs to do the interdependent calculation, doesn’t it? I’m just not at all clear that we could move the interdependent code fromLogFormatter.__call__ into this function without breaking someone’s code. I’m also not clear what now goes in__call__

@anntzer
Copy link
ContributorAuthor

ForConciseDateFormatter, you'd just write a stub__call__ that callsformat_ticks and extracts the single relevant value (perhaps the base__call__ could even check whetherformat_ticks is overridden by the subclass (the check is necessary to avoid infinite recursion betweenformat_ticks and__call__...), and, if it is, defer to it -- it's not that hard to do). Yes, that's a bit slower, but that only affects third party callers and simplifies the implementation quite a bit so I think it's worth it.
With this design, one would need to implement either__call__ orformat_ticks, but not both (ignoring issues such as formattingcursor values, which can also be fixed). For LogFormatter we just need to check whether it's indeed better to move the logic toformat_ticks (and again just make__call__ defer to it).

@jklymak
Copy link
Member

So, can you implementLogFormatter with the new method?

@tacaswelltacaswell added this to thev3.1 milestoneDec 3, 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.

modulo an api_changes or whats_new entry.

@jklymak
Copy link
Member

As per above - needs change log and ideally a real-world example...

Copy link
Member

@efiringefiring left a comment

Choose a reason for hiding this comment

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

Apart from the one suggested API change, and the need for an API note, I like this.

@anntzer
Copy link
ContributorAuthor

The real-world example is basically ConciseDateFormatter (happy to rewrite it using this API after the ConciseDateFormatter is merged).

@jklymak
Copy link
Member

Happy to do it the other way around if that makes more sense.

@anntzer
Copy link
ContributorAuthor

I think it makes more sense to get ConciseDate in first and then we'll be better able to see whether this PR fixes the design properly, or if we need some other API.

@jklymak
Copy link
Member

ping@anntzer ConciseDateFormatter is now in, so this can be looked at again?

I'm not sure how this plays with the issues of the minor locator ignoring major ticks. They are separate issues, right?

@anntzer
Copy link
ContributorAuthor

Pushed an adaptation of ConciseDateFormatter using the format_ticks API, it is a bit simpler.
This PR only touches formatters, so has nothing to do with locators.

@jklymak
Copy link
Member

LGTM! Still needs the API change note?

This is useful especially when labels are interdependent (e.g.ConciseDateFormatter, but also LogFormatter which currently relies onset_locs, etc.).Because `set_major_formatter`/`set_minor_formatter` (somewhat unusually)enforces that its argument is a Formatter subclass, even third-partyformatters will inherit from the base class and have this methoddefined.
@anntzer
Copy link
ContributorAuthor

added whatsnew

@anntzer
Copy link
ContributorAuthor

I think I made a mistake while reimplementing ConciseDateFormatter; namely, the "compression" should be used regardless of whether show_offset is True or False and show_offset only controls whether offset_string is set. Force-pushed a fix restoring the behavior as intended by@jklymak.

@jklymak
Copy link
Member

ooops, thanks for catching that....

@anntzer
Copy link
ContributorAuthor

Travis failure is the unrelated, spurious wqy-zenhei.ttc test.

@efiringefiring merged commit64c84b4 intomatplotlib:masterJan 29, 2019
@anntzeranntzer deleted the format_ticks branchJanuary 29, 2019 16:24
@LevN0
Copy link
Contributor

LevN0 commentedFeb 1, 2019
edited
Loading

Apologies if not the right place. This PR has the following side effect:

fig,ax=plt.subplots()data=np.clip(randn(250,250)*1000,0,1000)cax=ax.imshow(data,norm=mpl.colors.LogNorm(vmin=1,vmax=1000))cbar=fig.colorbar(cax,format='%d')cbar.minorticks_off()cbar.set_ticks([5,10,100])plt.show()

Prior to this PR, minor ticks would remain off afterset_ticks when they had been turned off. After this PR, they come back on.

Edit: Comment is wrong, this PR did not change this.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@efiringefiringefiring approved these changes

@tacaswelltacaswelltacaswell approved these changes

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.1.0
Development

Successfully merging this pull request may close these issues.

5 participants
@anntzer@jklymak@LevN0@efiring@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp