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
Added a find_all method to the RcParams dictionary. #1861
Conversation
Cool feature. 👍 from me. |
@pelson, while you are at it, you might add a method (maybe with a pyplot function), perhaps "show_all(...)", which would use this selection to return a nicely formatted string with the keys and their current values. |
""" | ||
return RcParams((key, value) | ||
for key, value in self.items() | ||
if key_contains in key) |
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 key_contains.lower()
, and the doc string updated to make it clear the search is case insensitive? Here I am assuming all the rcparams are lower case, so correct me if I'm wrong.
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've not done this as I've gone for the regular expression route. I didn't want to make it too magic, and the user can always lower the string they are passing themselves if they are doing it programatically...
Let me know if you really want this feature.
This is beautiful. This will save me from having to search through the matplotlibrc file by hand.
Also, in addition to @efiring's suggestion, might it be worth to have a search for pyplot functions, too? Note, this is just a thought that should be in a separate PR if a consensus is reached. |
Personally I wouldn't use the pyplot function and I'm a hesitant to add more stuff there if possible, but I'd certainly make use of a Something like:
I'd also be happy to add a |
Ok, I've added some bells and whistles to this PR. I expect the new functionality means that the Cheers, |
def find_all(self, pattern): | ||
""" | ||
Return the subset of this RcParams dictionary for which the given | ||
``pattern`` string is found, by :func:`re.search`, somewhere in the key. |
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 find this a little bit unclear.
Maybe just say "pattern is a Python regular expression".
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.
Thanks @mdboom. I'll change to:
Return the subset of this RcParams dictionary whose keys match,
using :func:`re.search`, the given "pattern".
I'm happy to iterate on this though if you have further improvements?
Ok. I think that is all the actions taken care of. I think this is good to go. |
Needs a rebase. |
Thanks @mdboom - done. |
my initial reaction is against using regular expressions: to quote @yesthatjwz:
I can't think of a time when I will want the full power of a regular expression for searching the rcParams, but I can imagine wanting to find all instances of something with a period in the name, and be annoyed every time that I have to escape it. Edit: I have code like this for grabbing portions of rcParam keys so I can set them, or do something else with them:
|
indent = len(class_name) + 1 | ||
repr_split = pprint.pformat(dict(self), indent=1, width=80 - indent).split('\n') | ||
repr_indented = ('\n' + ' ' * indent).join(repr_split) | ||
return '{}({})'.format(class_name, repr_indented) |
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 style of formatting is not supported in python2.6
In [5]: '{}({})'.format('sorry', '>= 2.7 only')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-b84304fedd68> in <module>()
----> 1 '{}({})'.format('sorry', '>= 2.7 only')
ValueError: zero length field name in format
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.
Thanks @ivanov - travis spotted this one too - I'm always making this mistake! Bring on ending support for 2.6 😉
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.
Phil Elson, on 2013-04-12 12:32, wrote:
Thanks @ivanov - travis spotted this one too -
Good thing Travis spotted it as well, though sometimes it's easy
to ignore that person, since, as we've seen in the past, Travis
isn't always very reliable ;)
Bring on ending support for 2.6 😉
You won't hear complaints from me about it. Machines where I'm
still running 2.6 are not ones I will be updating matplotlib.
Agreed. I would be happy if we could just simply use the globbing syntax. |
I'm not wed to any particular form. I can see arguments for and against all 3 of the proposed solutions ( |
well, this bikeshedding won't be very fun if you're always going to be so agreeable, Phil! ;) I trust your decision, and do not feel strongly either way. My initial reaction was a worry that I'd have to write "font" or something like that, but that's not the case with any of the proposals on the table. So just that formatting thing needs to be fixed, and if you want to switch the way the matching works, that too, but it's fine as is, too. And then it's 🍰 + 🍴 for you @pelson |
Sadly, this is the case with the globbing syntax, otherwise I would have gone with @WeatherGod's nice suggestion.
Nomnom... anyone care to merge 😄 |
Added a find_all method to the RcParams dictionary.
@@ -706,8 +706,8 @@ class RcParams(dict): | |||
:mod:`matplotlib.rcsetup` | |||
""" | |||
|
|||
validate = dict([ (key, converter) for key, (default, converter) in \ | |||
defaultParams.iteritems() ]) | |||
validate = dict((key, converter) for key, (default, converter) in \ |
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 know this has been merged already, but I only just saw this trailing backslash.
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.
Thanks for finding. I have just fixed directly on 1.3.x
in `
207469f
I find I want to search for RcParams by keyword quite frequently.
Now you can do: