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

Create a hidden colorbar on-the-fly to format imshow cursor data if no colorbar exists yet.#12473

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

Closed

Conversation

anntzer
Copy link
Contributor

PR Summary

Followup to#12459, which also works when no colorbar exists. Adds a second commit on top of#12459.

Made as a separate PR as it's a bit an ugly hack (optimally we'd factor out the formatter selection) but still proposing it as I think the behavior is quite nice.

I don't think it'd be a performance issue as we don't actually draw() the hidden figure -- it doesn't even have a renderer attached to it.

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

@anntzeranntzer added this to thev3.1 milestoneOct 10, 2018
@jklymak
Copy link
Member

Why don’t you just add a formatter to the artist? This API May be preferable anyways to using the colorbar formatter though that could be the default.

@anntzer
Copy link
ContributorAuthor

Because the correct Formatter depends on the Normalization subclass being used, and that logic currently only exists in the colorbar code (nowhere else does it say that LogNorm should use LogFormatter, etc.).

@jklymak
Copy link
Member

Can’t we refactor that somehow? Seems quite hacky that you have to create a colorbar to make this work.

timhoffm reacted with thumbs up emoji

@anntzer
Copy link
ContributorAuthor

anntzer commentedOct 10, 2018
edited
Loading

The relationship between norms, scales, colorbars, locators and formatters has been discussed to death (although in a slightly deconstructed fashion) a few times e.g. in#7294 (#7294 (comment),#7294 (comment), ...); TLDR: I think Norms and Scales should be the same thing.
But I stared too many times at the colorbar code trying to refactor it and in the meantime this is the simplest I can do.

@jklymak
Copy link
Member

I think the relevant code for matching up the Norm and Formatter is just:

ifformatisNone:
ifisinstance(self.norm,colors.LogNorm):
self.formatter=ticker.LogFormatterSciNotation()
elifisinstance(self.norm,colors.SymLogNorm):
self.formatter=ticker.LogFormatterSciNotation(
linthresh=self.norm.linthresh)
else:
self.formatter=ticker.ScalarFormatter()

Can't we just makecolorbar._get_formatter_(norm) and call here and incolorbar?

@anntzer
Copy link
ContributorAuthor

No, youalso need to have an underlying axes that sets the locs for the formatter (that'slist(ax.yaxis.iter_ticks()) in this PR), otherwise the formatter can't format the values (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/ticker.py#L562).

@jklymak
Copy link
Member

You are right, but that seems quite unfortunate.

I think most places whereself.axis.get_view_internal() is called could be changed tomin/max(self.locs) ifself.axis isNone. Then all you'd have to do is manually set the view limits. I understand why we'd generally want to defer to the viewlimits, but its a shame to not allow the formatters to be independent of an axis if possible.

How does this work with lognorms anyways? The log formatter returns empty strings a lot of the time.

@jklymak
Copy link
Member

Oooh, doesFormatter.create_dummy_axis help?

@timhoffm
Copy link
Member

Didn't have time to look at the code, but I agree with@jklymak that this sounds extremely hacky. If it's not simple to refactor: What happens if we do not implement this? Does something crash or do we just not have the output displayed?

@jklymak
Copy link
Member

importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.tickerasmtickerfmt=mticker.ScalarFormatter()fmt.create_dummy_axis()fmt.set_locs([0.01,1000])print('Scalar:',fmt(20))fmt=mticker.LogFormatterSciNotation()fmt.create_dummy_axis()fmt.set_locs([0.01,1000])print('10:',fmt(10))print('20:',fmt(20))print('100:',fmt(100))print('200:',fmt(200))

Gives:

Scalar: 2010: $\mathdefault{10^{1}}$20:100: $\mathdefault{10^{2}}$200:

As above, not sure you even ever want to LogFormatter, but maybe I'm misunderstanding how this works...

@anntzer
Copy link
ContributorAuthor

anntzer commentedOct 11, 2018
edited
Loading

@jklymak Actually, you need to call fmt.axis.set_view_interval (instead of fmt.set_locs).

import numpy as npimport matplotlib.pyplot as pltimport matplotlib.ticker as mtickerfmt = mticker.ScalarFormatter()fmt.create_dummy_axis()fmt.axis.set_view_interval(0.01, 1000)print('Scalar:', fmt(20))fmt = mticker.LogFormatterSciNotation()fmt.create_dummy_axis()fmt.axis.set_view_interval(0.01, 1000)print('10:', fmt(10))print('20:', fmt(20))print('100:', fmt(100))print('200:', fmt(200))

gives

Scalar: False None 1.010: $\mathdefault{10^{1}}$False None 2.020: $\mathdefault{2\times10^{1}}$False None 1.0100: $\mathdefault{10^{2}}$False None 2.0200: $\mathdefault{2\times10^{2}}$

(I guess I should add a\times -> x in strip_math... now added to#12459)

@timhoffm Then we just fallback on the old label string (which is much less useful):#12459 protects everything under aif self.colorbar anyways.

@jklymak
Copy link
Member

I still think we should create a dummy axis, not colorbar...Formatter.create_dummy_axis should be made to work, but I admit I haven't wrestled with it yet.

@jklymakjklymak modified the milestones:v3.1.0,v3.2.0Feb 26, 2019
@anntzer
Copy link
ContributorAuthor

Perhaps(??) things will become easier after the followup PRs after format_ticks get handled.

@tacaswelltacaswell modified the milestones:v3.2.0,v3.3.0Sep 4, 2019
@QuLogicQuLogic modified the milestones:v3.3.0,v3.4.0May 2, 2020
@QuLogicQuLogic modified the milestones:v3.4.0,v3.5.0Jan 22, 2021
@jklymakjklymak marked this pull request as draftMarch 27, 2021 19:17
@anntzer
Copy link
ContributorAuthor

Superseded by#20949.

@anntzeranntzer closed thisJan 2, 2022
@anntzeranntzer deleted the imshow-cursordata-2 branchJanuary 2, 2022 15:00
@QuLogicQuLogic removed this from thev3.6.0 milestoneSep 9, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@anntzer@jklymak@timhoffm@tacaswell@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp