-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Simplify tick creation #22850
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
Simplify tick creation #22850
Conversation
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 idea! Maybe worth an API change note?
Unsure. Who do we want to reach with the note? This is not affecting users or the working of downstream packages. The only people who could be interested are implementers of Axises. They might be able to remove their |
lib/matplotlib/axis.py
Outdated
OFFSETTEXTPAD = 3 | ||
# The class used to create tick instances. | ||
# Must be overwritten in subclasses. | ||
_TICK_CLASS = None |
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 think this needs to be uppercased.
You could also write
@_api.classproperty
def _tick_class(cls):
raise NotImplementedError(...)
and in the subclasses just directly assign _tick_class = XTick
.
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.
Lowercased.
IMHO It's a bit simpler if we define the attribute in the base class. A not-implemented property as a placeholder that is overwritten has a slightly nicer error handling but is more difficult to understand. Since there is only one usage where we need the error handling, let's keep it simple.
Agreed this doesn't really need an API change note. |
98fadf5
to
c389023
Compare
The tick class hierarchy has a standard mechanism for creating ticks via `_get_tick()` The only element that is changing in these functions is the tick class. All other logic is identical. This PR makes the tick class a class attribute of Axis so that we can use one generic `_get_tick` implementation across all Axis subclasses. Note that users/downstream libraries can still define their own `_get_tick()` methods on subclasses if they want to have a different behavior.
c389023
to
120328f
Compare
The tick class hierarchy has a standard mechanism for creating ticks
via
_get_tick()
The only element that is changing in these functionsis the tick class. All other logic is identical.
This PR makes the tick class a class attribute of Axis so that we can
use one generic
_get_tick
implementation across all Axis subclasses.Note that users/downstream libraries can still define their own
_get_tick()
methods on subclasses if they want to have a differentbehavior.