@@ -549,6 +549,7 @@ def _get_configdir():
549
549
configdir = os .environ .get ('MPLCONFIGDIR' )
550
550
if configdir is not None :
551
551
if not os .path .exists (configdir ):
552
+ from matplotlib .cbook import mkdirs
552
553
mkdirs (configdir )
553
554
if not _is_writable_dir (configdir ):
554
555
return _create_tmp_config_dir ()
@@ -631,9 +632,9 @@ def get_example_data(fname):
631
632
632
633
def get_py2exe_datafiles ():
633
634
datapath = get_data_path ()
634
- head , tail = os .path .split (datapath )
635
+ _ , tail = os .path .split (datapath )
635
636
d = {}
636
- for root , dirs , files in os .walk (datapath ):
637
+ for root , _ , files in os .walk (datapath ):
637
638
# Need to explicitly remove cocoa_agg files or py2exe complains
638
639
# NOTE I dont know why, but do as previous version
639
640
if 'Matplotlib.nib' in files :
@@ -647,7 +648,7 @@ def get_py2exe_datafiles():
647
648
648
649
def matplotlib_fname ():
649
650
"""
650
- Return the path to the rc file
651
+ Return the path to the rc file used by matplotlib.
651
652
652
653
Search order:
653
654
@@ -656,9 +657,7 @@ def matplotlib_fname():
656
657
* HOME/.matplotlib/matplotlibrc
657
658
* MATPLOTLIBDATA/matplotlibrc
658
659
659
-
660
660
"""
661
-
662
661
oldname = os .path .join (os .getcwd (), '.matplotlibrc' )
663
662
if os .path .exists (oldname ):
664
663
try :
@@ -820,13 +819,14 @@ def find_all(self, pattern):
820
819
821
820
822
821
def rc_params (fail_on_error = False ):
823
- 'Return the default params updated from the values in the rc file'
824
-
822
+ """Return a :class:`matplotlib.RcParams` instance from the
823
+ default matplotlib rc file.
824
+ """
825
825
fname = matplotlib_fname ()
826
826
if not os .path .exists (fname ):
827
827
# this should never happen, default in mpl-data should always be found
828
828
message = 'could not find rc file; returning defaults'
829
- ret = RcParams ([ (key , default ) for key , (default , converter ) in \
829
+ ret = RcParams ([(key , default ) for key , (default , _ ) in \
830
830
defaultParams .iteritems () ])
831
831
warnings .warn (message )
832
832
return ret
@@ -835,29 +835,31 @@ def rc_params(fail_on_error=False):
835
835
836
836
837
837
def rc_params_from_file (fname , fail_on_error = False ):
838
- """Load and return params from fname."""
839
-
838
+ """Return a :class:`matplotlib.RcParams` instance from the
839
+ contents of the given filename.
840
+ """
840
841
cnt = 0
841
842
rc_temp = {}
842
843
with open (fname ) as fd :
843
844
for line in fd :
844
845
cnt += 1
845
- strippedline = line .split ('#' ,1 )[0 ].strip ()
846
+ strippedline = line .split ('#' , 1 )[0 ].strip ()
846
847
if not strippedline : continue
847
- tup = strippedline .split (':' ,1 )
848
- if len (tup ) != 2 :
849
- warnings .warn ('Illegal line #%d\n \t %s\n \t in file "%s"' % \
848
+ tup = strippedline .split (':' , 1 )
849
+ if len (tup ) != 2 :
850
+ warnings .warn ('Illegal line #%d\n \t %s\n \t in file "%s"' % \
850
851
(cnt , line , fname ))
851
852
continue
852
853
key , val = tup
853
854
key = key .strip ()
854
855
val = val .strip ()
855
856
if key in rc_temp :
856
- warnings .warn ('Duplicate key in file "%s", line #%d' % (fname ,cnt ))
857
+ warnings .warn ('Duplicate key in file "%s", line #%d' % \
858
+ (fname , cnt ))
857
859
rc_temp [key ] = (val , line , cnt )
858
860
859
- ret = RcParams ([ (key , default ) for key , (default , converter ) in \
860
- defaultParams .iteritems () ])
861
+ ret = RcParams ([(key , default ) for key , (default , _ ) in \
862
+ defaultParams .iteritems ()])
861
863
862
864
for key in ('verbose.level' , 'verbose.fileo' ):
863
865
if key in rc_temp :
@@ -1033,20 +1035,20 @@ class rc_context(object):
1033
1035
1034
1036
This allows one to do::
1035
1037
1036
- >>> with mpl.rc_context(fname='screen.rc'):
1037
- ... plt.plot(x, a)
1038
- ... with mpl.rc_context(fname='print.rc'):
1039
- ... plt.plot(x, b)
1040
- ... plt.plot(x, c)
1038
+ with mpl.rc_context(fname='screen.rc'):
1039
+ plt.plot(x, a)
1040
+ with mpl.rc_context(fname='print.rc'):
1041
+ plt.plot(x, b)
1042
+ plt.plot(x, c)
1041
1043
1042
1044
The 'a' vs 'x' and 'c' vs 'x' plots would have settings from
1043
1045
'screen.rc', while the 'b' vs 'x' plot would have settings from
1044
1046
'print.rc'.
1045
1047
1046
1048
A dictionary can also be passed to the context manager::
1047
1049
1048
- >>> with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
1049
- ... plt.plot(x, a)
1050
+ with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
1051
+ plt.plot(x, a)
1050
1052
1051
1053
The 'rc' dictionary takes precedence over the settings loaded from
1052
1054
'fname'. Passing a dictionary only is also valid.
@@ -1133,7 +1135,7 @@ def use(arg, warn=True, force=False):
1133
1135
reload (sys .modules ['matplotlib.backends' ])
1134
1136
1135
1137
def get_backend ():
1136
- "Returns the current backend."
1138
+ """Return the name of the current backend."" "
1137
1139
return rcParams ['backend' ]
1138
1140
1139
1141
def interactive (b ):
0 commit comments