Skip to content

MatplotlibDeprecationWarning when updating rcparams #20249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gibbycu opened this issue May 17, 2021 · 6 comments · Fixed by #21042
Closed

MatplotlibDeprecationWarning when updating rcparams #20249

gibbycu opened this issue May 17, 2021 · 6 comments · Fixed by #21042

Comments

@gibbycu
Copy link

gibbycu commented May 17, 2021

Bug report

Bug summary
Updating RC params in code produces a deprecation warning. In order to control rcParams for an internal library I am reading in parameters and popping some that I don't want used. I am using a variation on the code below. I think I have traced it to the _validators dictionary in matplotlib.rcsetup.py

Code for reproduction
This code reproduces the error.

import matplotlib as mpl
rc = dict(mpl.rc_params())
mpl.rcParams.update(rc)

Actual outcome

C:\Users\User\miniconda3\envs\testmpl\lib\_collections_abc.py:841: MatplotlibDeprecationWarning: 
The datapath rcparam was deprecated in Matplotlib 3.2.1 and will be removed two minor releases later.
  self[key] = other[key]
C:\Users\User\miniconda3\envs\testmpl\lib\_collections_abc.py:841: MatplotlibDeprecationWarning: 
The savefig.frameon rcparam was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  self[key] = other[key]
C:\Users\User\miniconda3\envs\testmpl\lib\_collections_abc.py:841: MatplotlibDeprecationWarning: 
The text.latex.unicode rcparam was deprecated in Matplotlib 3.0 and will be removed in 3.2.
  self[key] = other[key]
C:\Users\User\miniconda3\envs\testmpl\lib\_collections_abc.py:841: MatplotlibDeprecationWarning: 
The verbose.fileo rcparam was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  self[key] = other[key]
C:\Users\User\miniconda3\envs\testmpl\lib\_collections_abc.py:841: MatplotlibDeprecationWarning: 
The verbose.level rcparam was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  self[key] = other[key]

Expected outcome
I would expect Matplotlib to not load deprecated rcParams

Matplotlib version

  • Operating system: Windows
  • Matplotlib version: 3.4.2
  • Matplotlib backend: 'Qt5Agg'
  • Python version: 3.9.4
  • Jupyter version (if applicable):
  • Other libraries:

Setup a conda environment and just specified matplotlib from conda-forge

@jklymak
Copy link
Member

jklymak commented May 17, 2021

Those were all removed in 3.4.2, and indeed are not loaded. I expect you have a crossed install somehow, and maybe an old matplotlibrc kicking around.

@jklymak jklymak added the status: needs clarification Issues that need more information to resolve. label May 17, 2021
@gibbycu
Copy link
Author

gibbycu commented May 17, 2021

I thought that too at first, but I don't believe that is the case here.

After more digging, it seems to be related to line 846 of __init__.py' which constructs the rcParamsDefault dictionary from the found matplotlibrc file AND the _hardcoded_defaults dictionary in rcsetup.py. It seems that when the matplotlibrc is loaded in rc_params_from_file() those deprecated params are injected behind the scenes with warnings depressed.

I suppose this is a feature to preserve behavior while in the deprecation period, but it is not expected (to me anyways). This behavior has puzzled me for years as my library reads, manipulates, and then updates rcparams (pre mplstyle era). I'd always find them even though my matplotlibrc and install was clean. I eventually countered this by maintaining a list of deprecated rcparams and popping them before my update. Not good for backward compatibility though. But then time would pass and more would crop up as versions changed and more future deprecations occurred. I finally posted here because it has become very cumbersome to manage.

@gibbycu
Copy link
Author

gibbycu commented May 17, 2021

Importing just matplotlib produces no warnings. It is only after the get and update.

@jklymak
Copy link
Member

jklymak commented May 17, 2021

For 3.4.2 the warning is:

/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]
/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]
/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The animation.html_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]
/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]
/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]
/Users/jklymak/anaconda3/envs/matplotlibdev/lib/python3.9/_collections_abc.py:856: MatplotlibDeprecationWarning: 
The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  self[key] = other[key]

I think that is working as we would expect, yes those entries still need to be in the dict, and yes you will get the deprecation message if you update them. I'm not sure we can do anything to fix this....

@gibbycu
Copy link
Author

gibbycu commented May 18, 2021

Seems like the conundrum for a fix was discussed in #13118. Now that I understand that behavior, it seems good.

The "fix" is probably just using best practices like the matplotlib.rc() method or matplotlib.rcParams["some key"] = "some value" to change global state, at least in my case. These create a warning if a deprecated parameter is set, which is good. The copy then update method is not great if you don't want to manage those warnings.

Perhaps helpful to developers would be a clarification to the documentation for matplotlib.rc_params() and matplotlib.rc_params_from_file() indicating that deprecated rcparams will be inserted when loading from the matplotlibrc or other file to preserve behavior during the deprecation period. Then point them to best practice for setting global parameters in the guide here

@tacaswell
Copy link
Member

@gibbycu would you be willing to open a PR making the changes to those docstrings that would have saved you here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants