@@ -742,8 +742,8 @@ class RcParams(dict):
742742 :mod:`matplotlib.rcsetup`
743743 """
744744
745- validate = dict ([ (key , converter ) for key , (default , converter ) in \
746- defaultParams .iteritems () ] )
745+ validate = dict ((key , converter ) for key , (default , converter ) in \
746+ defaultParams .iteritems ())
747747 msg_depr = "%s is deprecated and replaced with %s; please use the latter."
748748 msg_depr_ignore = "%s is deprecated and ignored. Use %s"
749749
@@ -774,6 +774,19 @@ def __getitem__(self, key):
774774 key = alt
775775 return dict .__getitem__ (self , key )
776776
777+ def __repr__ (self ):
778+ import pprint
779+ class_name = self .__class__ .__name__
780+ indent = len (class_name ) + 1
781+ repr_split = pprint .pformat (dict (self ), indent = 1 ,
782+ width = 80 - indent ).split ('\n ' )
783+ repr_indented = ('\n ' + ' ' * indent ).join (repr_split )
784+ return '{0}({1})' .format (class_name , repr_indented )
785+
786+ def __str__ (self ):
787+ return '\n ' .join ('{0}: {1}' .format (k , v )
788+ for k , v in sorted (self .items ()))
789+
777790 def keys (self ):
778791 """
779792 Return sorted list of keys.
@@ -786,7 +799,25 @@ def values(self):
786799 """
787800 Return values in order of sorted keys.
788801 """
789- return [self [k ] for k in self .iterkeys ()]
802+ return [self [k ] for k in self .keys ()]
803+
804+ def find_all (self , pattern ):
805+ """
806+ Return the subset of this RcParams dictionary whose keys match,
807+ using :func:`re.search`, the given ``pattern``.
808+
809+ .. note::
810+
811+ Changes to the returned dictionary are *not* propagated to
812+ the parent RcParams dictionary.
813+
814+ """
815+ import re
816+ pattern_re = re .compile (pattern )
817+ return RcParams ((key , value )
818+ for key , value in self .items ()
819+ if pattern_re .search (key ))
820+
790821
791822def rc_params (fail_on_error = False ):
792823 'Return the default params updated from the values in the rc file'
0 commit comments