Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6715f4c

Browse files
committed
Improved backend specification
svn path=/trunk/matplotlib/; revision=3472
1 parent 32abfcd commit 6715f4c

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

796780
def 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

802802
def 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

828840
verbose.report('matplotlib version %s'%__version__)

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ numerix : numpy # numpy, Numeric or numarray
244244
#savefig.facecolor : white # figure facecolor when saving
245245
#savefig.edgecolor : white # figure edgecolor when saving
246246

247+
#cairo.format : png # png, ps, pdf, svg
248+
247249
# tk backend params
248250
#tk.window_focus : False # Maintain shell focus for TkAgg
249251
#tk.pythoninspect : False # tk sets PYTHONINSEPCT

0 commit comments

Comments
 (0)