-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Specify custom tick space heuristic in MaxNLocator #11027
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1779,7 +1779,8 @@ class MaxNLocator(Locator): | |
integer=False, | ||
symmetric=False, | ||
prune=None, | ||
min_n_ticks=2) | ||
min_n_ticks=2, | ||
tick_space_heuristic=None) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
|
@@ -1821,6 +1822,12 @@ def __init__(self, *args, **kwargs): | |
Relax `nbins` and `integer` constraints if necessary to | ||
obtain this minimum number of ticks. | ||
|
||
*tick_space_heuristic* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest that this just be another option for nbins. i.e. if nbins is callable it is used to determine the heuristic... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great idea! |
||
Controls spacing of ticks through `axis.get_tick_space`. This must | ||
be a callable object that takes two parameters, the axis length and | ||
the label font size, both in pt units. Default value `None` will | ||
use the default x- or y-axis heuristic. | ||
|
||
""" | ||
if args: | ||
kwargs['nbins'] = args[0] | ||
|
@@ -1882,11 +1889,17 @@ def set_params(self, **kwargs): | |
self._extended_steps = self._staircase(self._steps) | ||
if 'integer' in kwargs: | ||
self._integer = kwargs['integer'] | ||
if 'tick_space_heuristic' in kwargs: | ||
tick_space_heuristic = kwargs['tick_space_heuristic'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine by me. I was just following the style used in the rest of the |
||
if tick_space_heuristic is not None: | ||
self._tickspace_kw = {'heuristic': tick_space_heuristic} | ||
else: | ||
self._tickspace_kw = {} | ||
|
||
def _raw_ticks(self, vmin, vmax): | ||
if self._nbins == 'auto': | ||
if self.axis is not None: | ||
nbins = np.clip(self.axis.get_tick_space(), | ||
nbins = np.clip(self.axis.get_tick_space(**self._tickspace_kw), | ||
max(1, self._min_n_ticks - 1), 9) | ||
else: | ||
nbins = 9 | ||
|
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.
This should be private I think.
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.
You mean prepend the function with an underscore?
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.
Yes.