Skip to content

Commit 9c5733e

Browse files
committed
Deprecate rcParams["datapath"] in favor of mpl.get_data_path().
The rcParam cannot be meaningfully set by the end user from their matplotlibrc or Python code.
1 parent 731e53d commit 9c5733e

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

doc/api/matplotlib_configuration_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Default values and styling
4545

4646
.. autofunction:: matplotlib_fname
4747

48+
.. autofunction:: get_data_path
49+
4850
Logging
4951
=======
5052

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,8 @@ The *clear_temp* parameter and attribute of `.FileMovieWriter` is
211211
deprecated. In the future, files placed in a temporary directory (using
212212
``frame_prefix=None``, the default) will be cleared; files placed elsewhere
213213
will not.
214+
215+
The ``datapath`` rcParam
216+
~~~~~~~~~~~~~~~~~~~~~~~~
217+
Use `.get_data_path` instead. (The rcParam is deprecated because it cannot be
218+
meaningfully set by an end user.)

lib/matplotlib/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,13 @@ def get_cachedir():
507507
return _get_config_or_cache_dir(_get_xdg_cache_dir())
508508

509509

510-
def _get_data_path():
511-
"""Return the path to matplotlib data."""
510+
@_logged_cached('matplotlib data path: %s')
511+
def get_data_path():
512+
"""Return the path to Matplotlib data."""
512513

513514
path = Path(__file__).with_name("mpl-data")
514515
if path.is_dir():
516+
defaultParams['datapath'][0] = str(path)
515517
return str(path)
516518

517519
cbook.warn_deprecated(
@@ -534,18 +536,12 @@ def get_candidate_paths():
534536

535537
for path in get_candidate_paths():
536538
if path.is_dir():
539+
defaultParams['datapath'][0] = str(path)
537540
return str(path)
538541

539542
raise RuntimeError('Could not find the matplotlib data files')
540543

541544

542-
@_logged_cached('matplotlib data path: %s')
543-
def get_data_path():
544-
if defaultParams['datapath'][0] is None:
545-
defaultParams['datapath'][0] = _get_data_path()
546-
return defaultParams['datapath'][0]
547-
548-
549545
def matplotlib_fname():
550546
"""
551547
Get the location of the config file.
@@ -602,6 +598,7 @@ def gen_candidates():
602598
_deprecated_remain_as_none = {
603599
'animation.avconv_path': ('3.3',),
604600
'animation.avconv_args': ('3.3',),
601+
'datapath': ('3.3',),
605602
}
606603

607604

@@ -839,8 +836,9 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
839836
if key not in _all_deprecated])
840837
config.update(config_from_file)
841838

842-
if config['datapath'] is None:
843-
config['datapath'] = get_data_path()
839+
with cbook._suppress_matplotlib_deprecation_warning():
840+
if config['datapath'] is None:
841+
config['datapath'] = get_data_path()
844842

845843
if "".join(config['text.latex.preamble']):
846844
_log.info("""

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def get_sample_data(fname, asfileobj=True):
486486
487487
If the filename ends in .gz, the file is implicitly ungzipped.
488488
"""
489-
path = Path(matplotlib._get_data_path(), 'sample_data', fname)
489+
path = Path(matplotlib.get_data_path(), 'sample_data', fname)
490490
if asfileobj:
491491
suffix = path.suffix.lower()
492492
if suffix == '.gz':

matplotlibrc.template

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@
9595
#toolbar: toolbar2 # {None, toolbar2}
9696
#timezone: UTC # a pytz timezone string, e.g., US/Central or Europe/Paris
9797

98-
## Where your matplotlib data lives if you installed to a non-default
99-
## location. This is where the matplotlib fonts, bitmaps, etc reside
100-
#datapath: /home/jdhunter/mpldata
101-
10298

10399
## ***************************************************************************
104100
## * LINES *

0 commit comments

Comments
 (0)