@@ -851,15 +851,18 @@ def _get_item(self, key, mode=None):
851851 else :
852852 return None
853853
854- def category (self , cat , * , context = False ):
854+ def category (self , cat , * , trimcat = True , context = False ):
855855 """
856856 Return a dictionary of settings beginning with the substring
857857 ``cat + '.'``.
858858
859859 Parameters
860860 ----------
861861 cat : str, optional
862- The `rc` settings category.
862+ The `rc` setting category.
863+ trimcat : bool, optional
864+ Whether to trim ``cat`` from the key names in the output
865+ dictionary. Default is ``True``.
863866 context : bool, optional
864867 If ``True``, then each category setting that is not found in the
865868 context mode dictionaries is omitted from the output dictionary.
@@ -868,16 +871,19 @@ def category(self, cat, *, context=False):
868871 if cat not in RC_CATEGORIES :
869872 raise ValueError (
870873 f'Invalid rc category { cat !r} . Valid categories are '
871- ', ' .join (map (repr , RC_CATEGORIES )) + '.' )
874+ ', ' .join (map (repr , RC_CATEGORIES )) + '.'
875+ )
872876 kw = {}
873877 mode = 0 if not context else None
874878 for rcdict in (rcParamsLong , rcParams ):
875879 for key in rcdict :
876- if not re .search ( f'^ { cat } [.] [^.]+$ ' , key ):
880+ if not re .match ( fr'\A { cat } \. [^.]+\Z ' , key ):
877881 continue
878882 value = self ._get_item (key , mode )
879883 if value is None :
880884 continue
885+ if trimcat :
886+ key = re .sub (fr'\A{ cat } \.' , '' , key )
881887 kw [key ] = value
882888 return kw
883889
0 commit comments