-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update AutoDateFormatter with locator #12470
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
Update AutoDateFormatter with locator #12470
Conversation
ddb55d2
to
a35c323
Compare
a35c323
to
9eda3db
Compare
lib/matplotlib/axis.py
Outdated
"matplotlib.ticker.Locator") | ||
self.isDefault_majloc = False | ||
self.major.locator = locator | ||
if (hasattr(self.get_major_formatter(), "_locator") and | ||
hasattr(self.get_major_formatter(), "_tz")): | ||
self.get_major_formatter()._locator = locator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be .set_locator(locator)
instead of ._locator
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Would you favour making locator
a public property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know, I was tripped up earlier in my stem PR by accessing something using a private attribute instead of its setter though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think this should happen in axis.py
at all, but should all happen in dates.py
, probably in AutoDateLocator.__call__()
where it can check if the locator on the self.axis
has changed. I'll actually block on this, but am willing to be argued with if its really not possible any other way...
lib/matplotlib/axis.py
Outdated
"matplotlib.ticker.Locator") | ||
self.isDefault_majloc = False | ||
self.major.locator = locator | ||
if (hasattr(self.get_major_formatter(), "_locator") and | ||
hasattr(self.get_major_formatter(), "_tz")): | ||
self.get_major_formatter()._locator = locator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think this should happen in axis.py
at all, but should all happen in dates.py
, probably in AutoDateLocator.__call__()
where it can check if the locator on the self.axis
has changed. I'll actually block on this, but am willing to be argued with if its really not possible any other way...
Yep, makes sense. I'll see what's possible. |
@jklymak The problem is that Formatters in general do not know whether they are used as major or minor formatters. Hence, while the formatter can find out from |
9621304
to
c62ea13
Compare
I'm not really following the minor locator hitch, and the test isn't particularly clear (at least to me). What use case breaks down if you don't keep track of the _ismajor flag? I don't mind Long-term, I think there are plans to make locators and formatters less independent, so this is one of those cases where making that more general would be helpful. |
Neither a formatter, nor a locator have knowledge about which ticks they are being used with. The usecase that would break down is probably this complete idea of being able to keep formatter and locator in sync automatically. The only alternative is see would be to have every formatter register itself to an axis, such that it could store whether it's minor or major formatter. That would surely affect the complete locator/formatter framework. |
Hmm, OK< then I wonder if the right solution here is to add a |
@jklymak Ok, so here is a third attempt now. I went for a method |
Yeah, but I think you want a getter as well, so that you dont' have to rely on AttributeErrors to know if the locator has been set or not (i.e. the default is to return |
Not sure I understand that. There will always be a locator being set, because you cannot instantiate the Of course this isn't foolproof, but it has never been. E.g. you can still create |
Sure, but in general it would be nice to have a way to get the locator associated w/ a formatter. |
Somehow I'm not happy about the idea of 90% of all formatters having a public method |
Sorry, I thought locator was a general argument for formatters, but its not. I think it should be. Some formatters take "loc", which is the same thing as taking the locator, but less flexible. I think they should be linked, but maybe implimenting that is too heavy a lift for this PR. The proposal here is a good stopgap, and all private so we can change later... |
PR Summary
When setting a date locator without setting a new formatter, the ticklabels become mostly useless.
This PR checks inside of the formatter call if the current locator is still the same as the one active on the axis and if not, sets its
_locator
to the new locator.Previously

With this PR
PR Checklist