@@ -776,28 +776,28 @@ def rcdefaults():
776776 """
777777 rcParams .update (rcParamsDefault )
778778
779- # Now allow command line to override
780-
781- # Allow command line access to the backend with -d (matlab compatible
782- # flag)
783-
784- for s in sys .argv [1 :]:
785- if s .startswith ('-d' ) and len (s ) > 2 : # look for a -d flag
786- be_parts = s [2 :].split ('.' )
787- try :
788- name = validate_backend (be_parts [0 ])
789- rcParams ['backend' ] = name
790- if name == 'Cairo' and len (be_parts ) > 1 :
791- rcParams ['cairo.format' ] = validate_cairo_format (be_parts [1 ])
792- except (KeyError , ValueError ):
793- pass
794- # we don't want to assume all -d flags are backends, eg -debug
795779
796780def use (arg ):
797781 """
798- Set the matplotlib backend to one of the known backends
782+ Set the matplotlib backend to one of the known backends.
783+
784+ The argument is case-insensitive. For the Cairo backend,
785+ the argument can have an extension to indicate the type of
786+ output. Example:
787+
788+ use('cairo.pdf')
789+
790+ will specify a default of pdf output generated by Cairo.
791+
792+ Note: this function must be called *before* importing pylab
793+ for the first time; or, if you are not using pylab, it must
794+ be called before importing matplotlib.backends.
799795 """
800- rcParams ['backend' ] = validate_backend (arg )
796+ be_parts = arg .split ('.' )
797+ name = validate_backend (be_parts [0 ])
798+ rcParams ['backend' ] = name
799+ if name == 'Cairo' and len (be_parts ) > 1 :
800+ rcParams ['cairo.format' ] = validate_cairo_format (be_parts [1 ])
801801
802802def get_backend ():
803803 return rcParams ['backend' ]
@@ -823,6 +823,18 @@ def tk_window_focus():
823823 return False
824824 return rcParams ['tk.window_focus' ]
825825
826+ # Now allow command line to override
827+
828+ # Allow command line access to the backend with -d (matlab compatible
829+ # flag)
830+
831+ for s in sys .argv [1 :]:
832+ if s .startswith ('-d' ) and len (s ) > 2 : # look for a -d flag
833+ try :
834+ use (s [2 :])
835+ except (KeyError , ValueError ):
836+ pass
837+ # we don't want to assume all -d flags are backends, eg -debug
826838
827839
828840verbose .report ('matplotlib version %s' % __version__ )
0 commit comments