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

Skip to content

Commit 5d637b2

Browse files
committed
Merge pull request #1491 from sandrotosi/v1.2.x
Reintroduce examples.directory rc parameter
2 parents 067e992 + 0b7e9b1 commit 5d637b2

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/matplotlib/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,20 @@ def rc_params_from_file(fname, fail_on_error=False):
823823
# this is the instance used by the matplotlib classes
824824
rcParams = rc_params()
825825

826+
if rcParams['examples.directory']:
827+
# paths that are intended to be relative to matplotlib_fname()
828+
# are allowed for the examples.directory parameter.
829+
# However, we will need to fully qualify the path because
830+
# Sphinx requires absolute paths.
831+
if not os.path.isabs(rcParams['examples.directory']):
832+
_basedir, _fname = os.path.split(matplotlib_fname())
833+
# Sometimes matplotlib_fname() can return relative paths,
834+
# Also, using realpath() guarentees that Sphinx will use
835+
# the same path that matplotlib sees (in case of weird symlinks).
836+
_basedir = os.path.realpath(_basedir)
837+
_fullpath = os.path.join(_basedir, rcParams['examples.directory'])
838+
rcParams['examples.directory'] = _fullpath
839+
826840
rcParamsOrig = rcParams.copy()
827841

828842
rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \

lib/matplotlib/cbook.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import warnings
2222
from weakref import ref, WeakKeyDictionary
2323

24+
import matplotlib
2425

2526
import numpy as np
2627
import numpy.ma as ma
@@ -570,9 +571,17 @@ def get_sample_data(fname, asfileobj=True):
570571
`mpl-data/sample_data` directory. If *asfileobj* is `True`
571572
return a file object, otherwise just a file path.
572573
574+
Set the rc parameter examples.directory to the directory where we should
575+
look, if sample_data files are stored in a location different than
576+
default (which is 'mpl-data/sample_data` at the same level of 'matplotlib`
577+
Python module files).
578+
573579
If the filename ends in .gz, the file is implicitly ungzipped.
574580
"""
575-
root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
581+
if matplotlib.rcParams['examples.directory']:
582+
root = matplotlib.rcParams['examples.directory']
583+
else:
584+
root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
576585
path = os.path.join(root, fname)
577586

578587
if asfileobj:

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ def __call__(self, s):
616616
'keymap.xscale' : [['k', 'L'], validate_stringlist],
617617
'keymap.all_axes' : ['a', validate_stringlist],
618618

619+
# sample data
620+
'examples.directory' : ['', str],
621+
619622
# Animation settings
620623
'animation.writer' : ['ffmpeg', validate_movie_writer],
621624
'animation.codec' : ['mpeg4', str],

matplotlibrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
423423
#keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
424424
#keymap.all_axes : a # enable all axes
425425

426+
# Control location of examples data files
427+
#examples.directory : '' # directory to look in for custom installation
428+
426429
###ANIMATION settings
427430
#animation.writer : ffmpeg # MovieWriter 'backend' to use
428431
#animation.codec : mp4 # Codec to use for writing movie

0 commit comments

Comments
 (0)