Bring back the module level 'backend'#6095
Bring back the module level 'backend'#6095mdboom merged 4 commits intomatplotlib:masterfrom ericdill:module-level-backend
Conversation
The removal of the module level 'backend' broke ipython's pylab code. This is the first attempt to bring it back.
|
It is not entirely clear to me how to keep the module level |
| ''' | ||
| # Import the requested backend into a generic module object | ||
| if backend is None: | ||
| backend = matplotlib.get_backend() # validates, to match all_backends |
There was a problem hiding this comment.
calling matplotlib.get_backend() in this function was the main point of the PR that broke this. In either case (passed in arg or calling get_backend) the value just needs to be mirrored out to backend. If we only needed to read this value we would not need global as the function would correctly close over it.
There was a problem hiding this comment.
Ok, so if backend is None, use get_backend() and set the module level backend to the result, then keep going with this function?
|
|
||
| if backend.startswith('module://'): | ||
| backend_name = backend[9:] | ||
| if name is None: |
There was a problem hiding this comment.
I think
global backend
if name is None:
name = mpl.get_backend()
backend = namewill do the right thing here. It will always defer to an explicitly passed input and then fall back to get_backend which in the end just consults rcparams for the requested backend. Assigning to the variable marked global will change the object that the module-level attribute points at (with out the global it would just bind a local variable).
There was a problem hiding this comment.
Is there any guarantee that name, if not None, is anything sensible that you would want to set to backends.backend? For example, say I do pylab_setup('keyboard'). Obviously that's dumb since keyboard is not a valid mpl backend. How should pylab_setup handle this? I would imagine that you might want to do the global backend; backend=name at the very end right before the return?
|
Someone who is not me should look at this before it gets merged. |
Bring back the module level 'backend'
The removal of the module level 'backend' broke ipython's pylab code. @tacaswell can you have a look? Renamed the
pylab_setup()kwarg toname, so thatbackendcould be a global in this function.Closes #6092