Skip to content

Commit a4a0925

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 c0fca72 commit a4a0925

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
@@ -282,3 +282,8 @@ is deprecated, set the offset to 0 instead.
282282
``RendererCairo.fontweights``, ``RendererCairo.fontangles``
283283
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284284
... are deprecated.
285+
286+
The ``datapath`` rcParam
287+
~~~~~~~~~~~~~~~~~~~~~~~~
288+
Use `.get_data_path` instead. (The rcParam is deprecated because it cannot be
289+
meaningfully set by an end user.) This was deprecated only in 3.2.1.

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.
@@ -600,6 +596,7 @@ def gen_candidates():
600596
# listed in the rcParams (not included in _all_deprecated).
601597
# Values are tuples of (version,)
602598
_deprecated_remain_as_none = {
599+
'datapath': ('3.2.1',),
603600
'animation.avconv_path': ('3.3',),
604601
'animation.avconv_args': ('3.3',),
605602
'mathtext.fallback_to_cm': ('3.3',),
@@ -841,8 +838,9 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
841838
if key not in _all_deprecated])
842839
config.update(config_from_file)
843840

844-
if config['datapath'] is None:
845-
config['datapath'] = get_data_path()
841+
with cbook._suppress_matplotlib_deprecation_warning():
842+
if config['datapath'] is None:
843+
config['datapath'] = get_data_path()
846844

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

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def get_sample_data(fname, asfileobj=True):
474474
475475
If the filename ends in .gz, the file is implicitly ungzipped.
476476
"""
477-
path = Path(matplotlib._get_data_path(), 'sample_data', fname)
477+
path = Path(matplotlib.get_data_path(), 'sample_data', fname)
478478
if asfileobj:
479479
suffix = path.suffix.lower()
480480
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)