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
[Bug]: Setting backend in custom style sheet raises UserWarning #20800
Comments
rcParams can be set with your matplotlibrc file, but as you can see some are expressly forbidden from the style files, which are meant for machine-independent styling. Maybe reread the docs, and get back to us with how we can make it more clear? |
Thank you for your reply. In Selecting a backend, the first of the three options says that you can set "The rcParams["backend"] parameter in your matplotlibrc file". An explicit example is following, where the Edit: Edit 2: First, the sentence
in Using style sheets could be changed to something like this:
Second, the link to Customizing Matplotlib with style sheets and rcParams in the first example in Selecting a backend could be changed to directly link to The matplotlibrc file. But anyhow, this is just my opinion. Feel free to close this issue. |
@andthum You are currently in the best position to understand how to fix the Matplotlib docs! Maintainers tend to end up being too steeped in the library to clearly see what is confusing (because there is too much other context in our heads). Sorry this tripped you up, it is indeed confusing. The matplotlib/lib/matplotlib/style/core.py Lines 43 to 48 in 3e32cc7
for the list of banned keys. I'm not sure what the best approach here is. Adding a hedge is not great (because then the reader is unsure about what keys will work), but listing out all of the keys that don't work inline is also not great (because many users reading this may need to even know that these keys exist!). Probably in the style module we should document the full banned list (maybe in the docstring of I think there are two actionable things to be done here:
Would you be interested in taking those on @andthum ? As a side point, as long as you are not using a GUI the backend does not super matter because |
@tacaswell Yes, I can try to clarify the docs and the warning message. Maybe tomorrow I can find time to do this. I will document the style blacklist in the docstring of |
Bug summary
Importing a custom style sheet where the
backend
rcParam is set withplt.style.use("custom_style.mplstyle")
raises the following warning and the backend remainsAgg
although it was set toPDF
incustom_style.mplstyle
.This is quite strange, because the latest docs suggest to switch the backend via a (custom) style sheet (https://matplotlib.org/stable/tutorials/introductory/customizing.html, https://matplotlib.org/stable/tutorials/introductory/usage.html#selecting-a-backend) and
backend
is listed as valid rcParam (https://matplotlib.org/stable/api/matplotlib_configuration_api.html#matplotlib.RcParams).Other rcParams (e.g.
backend_fallback
,interactive
orsavefig.directory
) trigger a UserWarning, too.This is related too Issue #5777 which describes the same problem for the default style sheet.
Code for reproduction
Actual outcome
The above mentioned UserWarning is raised, the backend remains
Agg
.Expected outcome
The PDF backend should be loaded silently.
Operating system
Ubuntu 20.04.2
Matplotlib Version
3.4.2
Matplotlib Backend
Agg, PDF
Python version
3.8.10
Jupyter version
No response
Other libraries
Clean install of matplotlib in a fresh virtual environment:
Installation
pip
Conda channel
No response
The text was updated successfully, but these errors were encountered: