Skip to content

Commit ea63c99

Browse files
adrntonysyu
authored andcommitted
fix url rc specification
smoothed over conflicts add test for URL stylesheet whoops, remove extraneous regex I added... move test to proper location arg, don't need urllib2 either...didn't realize functionality was in core mpl
1 parent 7392ce6 commit ea63c99

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/matplotlib/style/core.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
STYLE_EXTENSION = 'mplstyle'
3030
STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION)
3131

32-
3332
def is_style_file(filename):
3433
"""Return True if the filename looks like a style file."""
3534
return STYLE_FILE_PATTERN.match(filename) is not None
@@ -49,15 +48,18 @@ def use(name):
4948
name = [name]
5049

5150
for style in name:
52-
if is_style_file(style):
53-
settings = rc_params_from_file(style, use_default_template=False)
54-
mpl.rcParams.update(settings)
55-
elif style not in library:
56-
msg = ("'%s' not found in the style library. "
57-
"See `style.available` for list of available styles.")
58-
raise ValueError(msg % style)
59-
else:
51+
if style in library:
6052
mpl.rcParams.update(library[style])
53+
else:
54+
try:
55+
settings = mpl.rc_params_in_file(style)
56+
mpl.rcParams.update(settings)
57+
except:
58+
msg = ("'%s' not found in the style library and input is "
59+
"not a valid URL. See `style.available` for list of "
60+
"available styles.")
61+
raise ValueError(msg % style)
62+
6163

6264

6365
@contextlib.contextmanager

lib/matplotlib/tests/test_style.py

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def test_use():
4646
style.use('test')
4747
assert mpl.rcParams[PARAM] == VALUE
4848

49+
def test_use_url():
50+
with temp_style('test', DUMMY_SETTINGS):
51+
style.use('https://gist.github.com/adrn/6590261/raw')
52+
53+
assert mpl.rcParams['axes.facecolor'] == "adeade"
4954

5055
def test_context():
5156
mpl.rcParams[PARAM] = 'gray'

0 commit comments

Comments
 (0)