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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
643c74b
Add easy style sheet selection.
tonysyu Jul 21, 2013
3270aa4
Add rc_params_in_file to return partially-filled RcParams
tonysyu Jul 21, 2013
d83a03c
Rename style files to `*.style`
tonysyu Jul 21, 2013
c8cc486
Allow style.use to open URLs
tonysyu Jul 21, 2013
455b54c
Remove pyplot import
tonysyu Jul 21, 2013
7769b29
Add style context manager and tests
tonysyu Jul 23, 2013
3914089
Change style extension to *.mplstyle
tonysyu Jul 23, 2013
c3fae2e
Got a little crazy with the whitespace
tonysyu Jul 23, 2013
a3de231
Add style package and data to setupext.py
tonysyu Jul 25, 2013
d56f73e
Move test so that it actually runs.
tonysyu Sep 19, 2013
ec6ce6b
Use explicit string check
tonysyu Sep 19, 2013
5fdc037
Hide rc_params_in_file from parent namespace
tonysyu Sep 19, 2013
0c7437c
Remove usage of import *
tonysyu Sep 19, 2013
200d2e0
Clarify docstring
tonysyu Sep 19, 2013
7392ce6
added `matplotlib.style` to pyplot import list
tacaswell Sep 27, 2013
ea63c99
fix url rc specification
adrn Sep 17, 2013
eaa23ee
fixed divergent naming scheme
tacaswell Sep 27, 2013
5f80ca1
pep8 clean up
tacaswell Sep 27, 2013
f5ecf5e
Add docs for style package
tonysyu Sep 29, 2013
a8ef5bf
Import style package for easy use.
tonysyu Sep 29, 2013
dc291e0
Use style package from pyplot
tonysyu Sep 29, 2013
c5b5bb4
Fix test
tonysyu Sep 29, 2013
7ac26ee
pep8
tacaswell Oct 18, 2013
46a725b
Clear style settings between tests
mdboom Sep 30, 2013
d372a35
Add note that style sheets are experimental.
tonysyu Oct 19, 2013
e714c77
added python3 emulation code + six + fixed up print calls
tacaswell Oct 27, 2013
512b77c
removed unneeded print statements
tacaswell Oct 31, 2013
17282c8
Attempt to fix python 3 test errors on Travis CI
tonysyu Nov 13, 2013
a6142fc
Remove test from list to test Travis CI failure.
tonysyu Nov 14, 2013
19e7bed
Remove test file to test Travis CI failure
tonysyu Nov 14, 2013
c604498
Revert commits used to test Travis CI test failures.
tonysyu Nov 14, 2013
0b098e2
Fix import for python 3
tonysyu Nov 17, 2013
7e2bffb
Use iteritems from `six` module
tonysyu Nov 17, 2013
1d87f34
Add compatibility layer for Python 3's urlopen
tonysyu Nov 17, 2013
79f83c9
Fix _fix_url on Python 2.6
mdboom Nov 18, 2013
246c348
Merge pull request #6 from mdboom/style/py26-fixes
tonysyu Nov 18, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add rc_params_in_file to return partially-filled RcParams
This allows style sheets to update the current settings instead of overwriting them.
  • Loading branch information
tonysyu committed Nov 17, 2013
commit 3270aa4a96eb5f28fd8d5a01e737fe4e715d5373
78 changes: 54 additions & 24 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,14 @@ def rc_params(fail_on_error=False):
return rc_params_from_file(fname, fail_on_error)


def rc_params_from_file(fname, fail_on_error=False):
"""Return a :class:`matplotlib.RcParams` instance from the
contents of the given filename.
_error_details_fmt = 'line #%d\n\t"%s"\n\tin file "%s"'


def rc_params_in_file(fname, fail_on_error=False):
"""Return :class:`matplotlib.RcParams` from the contents of the given file.

Unlike `rc_params_from_file`, the configuration class only contains the
parameters specified in the file (i.e. default values are not filled in).
"""
cnt = 0
rc_temp = {}
Expand All @@ -891,8 +896,8 @@ def rc_params_from_file(fname, fail_on_error=False):
if not strippedline: continue
tup = strippedline.split(':', 1)
if len(tup) != 2:
warnings.warn('Illegal line #%d\n\t%s\n\tin file "%s"' % \
(cnt, line, fname))
error_details = _error_details_fmt % (cnt, line, fname)
warnings.warn('Illegal %s' % error_details)
continue
key, val = tup
key = key.strip()
Expand All @@ -902,34 +907,35 @@ def rc_params_from_file(fname, fail_on_error=False):
(fname, cnt))
rc_temp[key] = (val, line, cnt)

ret = RcParams([(key, default) for key, (default, _) in \
six.iteritems(defaultParams)])
config = RcParams()

for key in ('verbose.level', 'verbose.fileo'):
if key in rc_temp:
val, line, cnt = rc_temp.pop(key)
if fail_on_error:
ret[key] = val # try to convert to proper type or raise
config[key] = val # try to convert to proper type or raise
else:
try: ret[key] = val # try to convert to proper type or skip
try:
config[key] = val # try to convert to proper type or skip
except Exception as msg:
warnings.warn('Bad val "%s" on line #%d\n\t"%s"\n\tin file \
"%s"\n\t%s' % (val, cnt, line, fname, msg))

verbose.set_level(ret['verbose.level'])
verbose.set_fileo(ret['verbose.fileo'])
error_details = _error_details_fmt % (cnt, line, fname)
warnings.warn('Bad val "%s" on %s\n\t%s' %
(val, error_details, msg))

for key, (val, line, cnt) in six.iteritems(rc_temp):
if key in defaultParams:
if fail_on_error:
ret[key] = val # try to convert to proper type or raise
config[key] = val # try to convert to proper type or raise
else:
try: ret[key] = val # try to convert to proper type or skip
try:
config[key] = val # try to convert to proper type or skip
except Exception as msg:
warnings.warn('Bad val "%s" on line #%d\n\t"%s"\n\tin file \
"%s"\n\t%s' % (val, cnt, line, fname, msg))
error_details = _error_details_fmt % (cnt, line, fname)
warnings.warn('Bad val "%s" on %s\n\t%s' %
(val, error_details, msg))
elif key in _deprecated_ignore_map:
warnings.warn('%s is deprecated. Update your matplotlibrc to use %s instead.'% (key, _deprecated_ignore_map[key]))
warnings.warn('%s is deprecated. Update your matplotlibrc to use '
'%s instead.'% (key, _deprecated_ignore_map[key]))

else:
print("""
Expand All @@ -939,21 +945,45 @@ def rc_params_from_file(fname, fail_on_error=False):
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
distribution""" % (key, cnt, fname), file=sys.stderr)

if ret['datapath'] is None:
ret['datapath'] = get_data_path()
return config




def rc_params_from_file(fname, fail_on_error=False):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between rc_params_from_file and rc_params_in_file are so minimal I'd be tempted to factor this into a keyword - something like use_default_template=True/False?

"""Return :class:`matplotlib.RcParams` from the contents of the given file.

Parameters
----------
fname : str
Name of file parsed for matplotlib settings.
fail_on_error : bool
If True, raise an error when the parser fails to convert a parameter.
"""

config = RcParams([(key, default)
for key, (default, _) in six.iteritems(defaultParams)])

config.update(rc_params_in_file(fname, fail_on_error))

verbose.set_level(config['verbose.level'])
verbose.set_fileo(config['verbose.fileo'])

if config['datapath'] is None:
config['datapath'] = get_data_path()

if not ret['text.latex.preamble'] == ['']:
if not config['text.latex.preamble'] == ['']:
verbose.report("""
*****************************************************************
You have the following UNSUPPORTED LaTeX preamble customizations:
%s
Please do not ask for support with these customizations active.
*****************************************************************
"""% '\n'.join(ret['text.latex.preamble']), 'helpful')
"""% '\n'.join(config['text.latex.preamble']), 'helpful')

verbose.report('loaded rc file %s'%fname)

return ret
return config


# this is the instance used by the matplotlib classes
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def read_style_directory(style_dir):
"""Return dictionary of styles defined in `style_dir`."""
styles = dict()
for path, name in iter_style_files(style_dir):
styles[name] = mpl.rc_params_from_file(path)
styles[name] = mpl.rc_params_in_file(path)
return styles


Expand Down