-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Proposed change to default log scale tick formatting #5161
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
It seems like you've combined the logic of whether to display a tick (which is usually the job of a Locator subclass) with the logic of how to display a tick (which is usually the job of a Formatter subclass). Any reason why you didn't separate concerns like all the other Locator/Formatters? Other than that, I see this as very useful, though we'll have to determine whether or not it's a good idea to change the default behavior. |
@mdboom: For the case of log-scaled axis, it is nice to show all minor ticks to make it clear that the scaling is logarithmic, but we obviously do not want to label all minor ticks. The current default is show all minor ticks and label none. I had to combine them so that all minor ticks are shown, but not all of them labeled. I understand its a departure from how other Locator/Formatter work, but I did not see a different way to do it. EDIT: I could not find it, but is there any other Locator/Formatter where this is done (i.e., only some of the shown minor or major ticks are labeled)? |
@zblz: I understand the problem better now. I think it could lead to confusion that the formatter chooses not to format some ticks, particularly if using an explicit locator or something. However, as you say, I can't think of a better way right now. That's all the more argument to keep the default for log scales as something that formats everything. Let me think on it for a bit -- maybe there is a better way, perhaps by adding the ability to have separate locators for ticks and text... |
Separate locators would be ideal for this case, but it would increase the complexity of the tick logic in By the way, I adapted this logic of not showing some labels from the only way I knew how to produce this previously, which was to use horrible, horrible ad-hoc labels like this:
|
What if a locator could signal whether the location is intended for On Tue, Oct 6, 2015 at 1:58 PM, Victor Zabalza notifications@github.com
|
@WeatherGod: I like that idea. |
@WeatherGod: It sounds good, but I have no idea of how to even begin to implement that from a glance at |
If one works from the assumption that all ticklabels must have a tickline, On Tue, Oct 6, 2015 at 2:15 PM, Victor Zabalza notifications@github.com
|
The |
@tacaswell: But if whether we return a label depends on |
Ok, I tried to move the print logic from the formatter to the locator following @WeatherGod's suggestion, and now the locator must return two arrays: the location for the ticks and whether each tick should be labeled. This means a change to all the |
re-milestoned this for 2.1 as this is not just changing some parameters. |
Change of mind right after pushing: I moved the logic on whether to show the labels to an different function than the |
To keep the focus of this PR, I have removed the functionality to plot |
Thanks. I think the separation of Locator/Formatter is much better now. One further refinement though -- I don't think we necessarily require that a Locator inherits from LocatorBase (matplotlib's built-in ones all do, but third-party ones may not). So we should be robust to the possibility that |
Thanks. I'm happy to merge this once the test failure is resolved. |
03aa5bc
to
4c2f76e
Compare
|
|
We could consider the default change as part of 2.0. Not promising anything, but that's a good window of opportunity for it. |
I would like to suggest re-milestoning this (or the original issue, #4867), for 2.0. When round-number limits were the default, a log-scale axis would by default be expanded to initially cover at least one (integer) decade, and thus have at least two labeled ticks (at the two ends). With the switch to margins-based limits, it is now possible for axes to default to having no labels at all (e.g. Edit: Changed the milestone, but feel free to discuss if you disagree. |
I have moved the logic back into the formatter classes, choosing to add it into I have also added back |
Getting a bunch of errors. Somehow, zeros are getting down into |
I have fixed the error on symlog axes, which where sending values |
The remaining error on |
power-cycling to test against the latest master. |
This is passing and is milestoned for v2.0. I don't know who is the one to approve the remaining style changes. |
API: Changes to default log scale tick formatting
backported to v2.x as fb45c4a |
Reverts part of matplotlib#5161 original commit merged to master as 947e6eb the merge was backported to v2.x as fb45c4a
This partly restores the functionality that was added in PR matplotlib#5161 and partly removed in matplotlib#7000. The "partly" is because now the labeling of minor log ticks is turned on only when numdecs (the axis range in powers of the log base) is less than or equal to one, rather than 3. This also fixes a bug that was causing double labeling with a base of 2; minor ticks were coinciding with major ticks, and both were being labeled.
Following #4730 and #4867, this is a proposal to change the defaults for the upcoming 2.0 release regarding the default tick label formatting for log-scaled axes. This is not a finished PR, but mean to initiate discussion on whether this is desired as default (if not I still think a similar thing could be worth having as an option).
LogFormatterSciNotation
) is used as default for all log-scaled axes. This formatter always prints all labels for the bases of the log scale (major ticks) and adds labels to the minor ticks as the axis view limits are made smaller (with a similar logic toLogLocator
withsubs=None
):(1, 3) * base**i
are labeled.(1, 2, 5) * base**i
are labeled.(1, 2, 4, 7) * base**i
are labeled.$ 3 \times 10^{-2} $
LogFormatter
).Example of this formatter in action:

The main motivation is to improve readability of the axis ticks when log-scaled axis are zoomed-in to less than a few decades, which under the current Formatters leaves only very few labels in the axis. Note that this does not change the formatting whenever more than 3 decades are spanned by the axis view limits.