-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
axes.locator_params fails with LogLocator (and most Locator subclasses) #3658 #4172
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
#3658 for github-foo linking looks good. Thanks for the exhaustive tests! My only comment is that it might be better if the Could you also add an entry in the https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new so that this improvement gets properly advertised? |
The reason for using kwargs was to mirror the set_param() function within MaxNLocator. Would it be prefered if I changed everything to explicitly list arguments? def explicitArgs(self, a=None, b=None):
if a is not None:
self.a = a
if b is not None:
self.b = b |
That is exactly what I had in mind. Could you also add doc-strings to all of those You are making a case to also re-work how the existing The existing implementation is mirroring in part how the |
@@ -1002,6 +1008,12 @@ def __init__(self, base, offset): | |||
self._base = base | |||
self.offset = offset | |||
|
|||
def set_params(self, **kwargs): | |||
if 'base' in kwargs: | |||
self.base = kwargs['base'] |
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 think this has to be _base
with an underscore; or remove the underscore elsewhere in this class.
Maybe some mechanization would help, instead of lots of boilerplate |
@tacaswell, to add a bit: I am thinking about using data structures (e.g. ordered dict) to handle default parameters and parameter documentation. It's hard to look at a bunch of |
I am mostly worried about the silently ignored, one of my co-workers (@ericdill ) has convinced me that doing that is rather user hostile. I think doing a I agree the We can't use ordereddicts until we drop 2.6 (or take care of the needed shimming). |
Thanks for all the input! def set_params(self, base=None, subs=None, numdecs=None, numticks=None):
"""Set parameters within this locator."""
args = locals()
for key, value in args.iteritems():
if value is not None:
setattr(self, key, value) The restriction is that the argument names must be exactly the same as the class's parameters. Are there better ways? I'm not familiar with |
@tacaswell, this is really calling out for a more comprehensive reworking. It doesn't necessarily have to be done now, but we need to make sure that what is done now doesn't constitute an API change that we have to support, if it is not one we will want to support. MaxNLocator is already headed in the right direction; it has a class-level dictionary of default parameters. I think that every Locator should have this, or at least some class-level data structure. Second, the MaxNLocator model is using set_params in its init as well as for later modification. I think this is important. What it's set_params is missing is merely a section at the top: badkw = set(kwargs.keys()) - set(self.default_params.keys())
if badkw:
raise ValueError("Invalid keyword arguments: " + ', '.join(badkw)) Third, there should be a The general approach could be used in more than just the |
I think this is starting to converge back to traitlets/IPython configurable/atom classes. We should sort of if we want to use one of the existing solutions to this before we roll our own. These get/set params function are also what we are going to need for serialization and are what will make doing the style-sheet like functionality possible. |
Yes, I took a quick look at traitlets, but I'm not convinced that they will be appropriate for what we need here. What is the "atom" class? |
https://github.com/nucleic/atom It is the same idea as traits/triatlets I suspect that that complexity provides things that we will want and end up On Sun, Mar 1, 2015 at 12:14 PM Eric Firing [email protected]
|
Enaml, for which Atom is built, looks like it might be nice--but it is py 2.7 only, with py 3 being low priority, and its development is Windows-oriented. Atom itself is very new. I conclude that we will not want a dependency on Atom. |
@tacaswell, I'm inclined to go along with this PR in its present straightforward form. We already have set_params on one locator, so regardless of what we do in the future, I don't see how we would be worse off having this method for all locators. @ryanbelt, this would involve a rebase and then adding set_params to the new LogitLocator that I just merged. |
…ator and IndexLocator
… testing functions to test_ticker.py
Alright. I rebased and added |
Sounds fine to me. The conversion to something like traitlets is going to On Tue, Mar 3, 2015, 14:42 leeonadoh [email protected] wrote:
|
axes.locator_params fails with LogLocator (and most Locator subclasses) #3658
@leeonadoh Would you make a PR with entries in doc/api/api_changes and doc/users/whats_new for this, please? Each of those directories has a README with instructions, and you can also look at the existing entries as examples. |
DOC : Adding 'api_changes' and 'whats_new' docs for PR #4172
set_param() function is now implemented in both Locator and its subtypes, following the suggestions of @tacaswell.
Test cases were implemented for all Locator classes where a set_param() function is added. Raised warnings are also accounted for in Locators that do not implement set_param() (i.e. NullLocator).