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

Skip to content

Commit 8059bdf

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 9c4e686 commit 8059bdf

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
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
@@ -184,3 +184,8 @@ Debian 8 (2015, EOL 06/2020) and Ubuntu 14.04 (EOL 04/2019) were the
184184
last versions of Debian and Ubuntu to ship avconv. It remains possible
185185
to force the use of avconv by using the ffmpeg-based writers with
186186
:rc:`animation.ffmpeg_path` set to "avconv".
187+
188+
The ``datapath`` rcParam
189+
~~~~~~~~~~~~~~~~~~~~~~~~
190+
Use `.get_data_path` instead. (The rcParam is deprecated because it cannot be
191+
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,8 +507,9 @@ 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
if 'MATPLOTLIBDATA' in os.environ:
514515
path = os.environ['MATPLOTLIBDATA']
@@ -521,6 +522,7 @@ def _get_data_path():
521522

522523
path = Path(__file__).with_name("mpl-data")
523524
if path.is_dir():
525+
defaultParams['datapath'][0] = str(path)
524526
return str(path)
525527

526528
cbook.warn_deprecated(
@@ -543,18 +545,12 @@ def get_candidate_paths():
543545

544546
for path in get_candidate_paths():
545547
if path.is_dir():
548+
defaultParams['datapath'][0] = str(path)
546549
return str(path)
547550

548551
raise RuntimeError('Could not find the matplotlib data files')
549552

550553

551-
@_logged_cached('matplotlib data path: %s')
552-
def get_data_path():
553-
if defaultParams['datapath'][0] is None:
554-
defaultParams['datapath'][0] = _get_data_path()
555-
return defaultParams['datapath'][0]
556-
557-
558554
def matplotlib_fname():
559555
"""
560556
Get the location of the config file.
@@ -611,6 +607,7 @@ def gen_candidates():
611607
_deprecated_remain_as_none = {
612608
'animation.avconv_path': ('3.3',),
613609
'animation.avconv_args': ('3.3',),
610+
'datapath': ('3.3',),
614611
}
615612

616613

@@ -848,8 +845,9 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
848845
if key not in _all_deprecated])
849846
config.update(config_from_file)
850847

851-
if config['datapath'] is None:
852-
config['datapath'] = get_data_path()
848+
with cbook._suppress_matplotlib_deprecation_warning():
849+
if config['datapath'] is None:
850+
config['datapath'] = get_data_path()
853851

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

matplotlibrc.template

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

106-
## Where your matplotlib data lives if you installed to a non-default
107-
## location. This is where the matplotlib fonts, bitmaps, etc reside
108-
#datapath : /home/jdhunter/mpldata
109-
110106

111107
## ***************************************************************************
112108
## * LINES *

0 commit comments

Comments
 (0)