-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
allow selecting the backend by setting the environment variable MPLBACKEND #3710
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
Conversation
Interesting, we look at envs when setting up the QT backend stuff, I assumed we already had something that did this... |
Another reason to like this... explicit setting of backends can be On Thu, Oct 23, 2014 at 4:08 PM, Thomas A Caswell notifications@github.com
|
|
I am tentatively 👍 on merging this. Don't understand all of this machinery well enough. |
This needs to be mentioned in the docs (someplace) and an entry in what's new. Someplace in the FAQ would probably be a good place "How do I control the backend" followed by the bullet points you have above. |
else: | ||
# no backend selected from the command line, so we check the environment | ||
# variable MPL_BACKEND | ||
if 'MPL_BACKEND' in os.environ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this line is superfluous, since you are catching KeyError.
I added some documentation in the Usage FAQ, where Also, I changed the name for the variable from |
@@ -325,7 +343,7 @@ binary installer or a linux distribution package, a good default | |||
backend will already be set, allowing both interactive work and | |||
plotting from scripts, with output to the screen and/or to | |||
a file, so at least initially you will not need to use either of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change either -> any
The failure is not related to any of your changes. I have restarted the failed job. |
I am working on some edits to the docs as well.. |
@FlorianRhiem There should be a PR against your branch from me with some more doc edits |
👍 in principle. Implementation looks good too but it does need a rebase. |
…of the methods -> any of the methods)
Made how to set backend an ordered list
I rebased the commits (only the punctuation in an inline comment was conflicting). All test jobs pass except for the first one, which seems to be a problem on Travis' side: |
I restated the failing job |
Just one last sanity check... doesn't matplotlib also support loading a On Mon, Nov 17, 2014 at 6:59 AM, Jens Hedegaard Nielsen <
|
@WeatherGod: Yes, the rc file is looked for in this order:
How does that impact this, though? |
@FlorianRhiem 's rationale for deciding on the priority of the setting:
The rcparam isn't as "global" as originally conceived because it might even be as specific as for the particular script in the directory. What priority should an environment variable have over a local matplotlibrc file? |
@WeatherGod: Thanks for clarifying, and I see your point. Don't have a good answer though -- maybe others here do. Regardless, we should probably document the whole priorities of the multitude of ways to set a backend in one place. |
So
In my opinion the latter case is the most useful application for an environment variable, because it allows the user to switch backends without editing a text file or adding a command line argument (and making sure it doesn't cause problems with I think most users will set the global default backend in an |
I don't see it the same way. It is very easy to add an environment variable to my bashrc file, as it is very typical to add such things there. I rarely set an environment variable for a particular command instance (although, I do admit that it is a much better alternative than the very bad argparse hijacking that we do). I would wager that very few people know about matplotlibrc, and fewer still know about per-directory matplotlibrc. But those who do know those things might expect the per-directory param to override the environment variable that was set in their bashrc file (because those are typically considered "global" in nature). Your use-case of setting the environment variable on a per-execution basis is entirely plausible, and it is entirely reasonable for the environment variable to override the rc param in such a case. It is entirely a problem with discerning intent from mixed information sources. We simply can't distinguish between an environment variable in a bashrc versus on given at the command-line. Perhaps we need two possible environment variables to cater to the two different use-cases. A low-priority, longer "global" variable for use in a bashrc, and a higher-priority, short variable (easy for typing) for per-execution uses? |
Those who know the environment variable should know the This does seem to make matters even more complicated though. So an alternative: The documentation should specifically and clearly recommend using the environment variable only locally (instead of the |
Ah, good point about the default backend variable always getting overriden by the default rc file installed by matplotlib. Ok, I think you have the right idea: offer the environment variable as the prefered alternative to the command line option (possibly even deprecating it, maybe?!), and making it clear the priorities. I would even go so far as to note in the documentation that the environment variable in a bashrc file would therefore override any backend settings in a per-directory matplotlibrc. |
I am in concurrence with the current order. This will also be very useful for people trying to run mpl behind djanjo On Mon, Nov 17, 2014, 13:33 Benjamin Root notifications@github.com wrote:
|
|
||
* with the use directive is your script:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is -> in
…ovements to the backend selection documentation.
Alright, I am +1 on this. Just a last check, @tacaswell, aren't "whats_new" entries supposed to go someplace else to reduce the need for other PRs to rebase? If it isn't that big of an issue, I can go ahead and press the green button. |
There is a whats_new folder that has a README to explain how it should work full of rst files that has been followed inconsistently. My current plan is to clean it up by hand next time we release anyway and be better about enforcing it going forward. I would not worry about that for this PR. |
Ok, understood. Merging! |
allow selecting the backend by setting the environment variable MPLBACKEND
This commit adds a new way of selecting the matplotlib backend. The
-d
flag can cause problems with scripts that use the command line arguments as parameters and don't ignore unknown ones. An environment variableMPL_BACKEND
can be set by the user (or in the code) and is far less likely to cause problems than using the-d
flag.