Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JRE - Modified 'use' so that it will only warn if the requested backend ... #1445

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

Merged
merged 1 commit into from
Nov 5, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
JRE - Modified 'use' so that it will only warn if the requested backe…
…nd is different that what is currently set.
  • Loading branch information
James R. Evans committed Nov 1, 2012
commit 6ccdbbc1cdc9563c48e2e345839cb6e115f30892
20 changes: 11 additions & 9 deletions 20 lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,18 @@ def use(arg, warn=True, force=False):
:func:`matplotlib.get_backend`.

"""
# Lets determine the proper backend name first
if arg.startswith('module://'):
name = arg
else:
# Lowercase only non-module backend names (modules are case-sensitive)
arg = arg.lower()
name = validate_backend(arg)

# Check if we've already set up a backend
if 'matplotlib.backends' in sys.modules:
if warn:
# Warn only if called with a different name
if (rcParams['backend'] != name) and warn:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete nit-pick: I would typically put the warn first - because it is as far simpler evaluation (is a boolean True or False vs get the value from the dictionary and compare the strings).

I do not expect you to make this change (it is so trivial and adds nothing to the PR), I just wanted to mention it for future consideration.

Thanks,

warnings.warn(_use_error_msg)

# Unless we've been told to force it, just return
Expand All @@ -1011,14 +1020,7 @@ def use(arg, warn=True, force=False):
else:
need_reload = False

# Set-up the proper backend name
if arg.startswith('module://'):
name = arg
else:
# Lowercase only non-module backend names (modules are case-sensitive)
arg = arg.lower()
name = validate_backend(arg)

# Store the backend name
rcParams['backend'] = name

# If needed we reload here because a lot of setup code is triggered on
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.