Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
implementation of mpl_init mechanism#30742
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
implementation of mpl_init mechanism#30742
Conversation
| # Initialize colormap registry (depends on rcParams['image.lut']) | ||
| frommatplotlibimportcm | ||
| ifhasattr(cm,'_mpl_init'): |
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.
We do not need conditionals on modules we control.
| # workaround: we must defer colormaps import to after loading rcParams, because | ||
| # colormap creation depends on rcParams | ||
| # Import colormap registries (they are now safely initialized via _mpl_init()) |
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.
If this is the case, can we move these imports to the top?
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.
I guess we should move the imports to the top and replace these lines with creating aliases?
| def_gen_cmap_registry(): | ||
| def_gen_cmap_registry(lutsize): |
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.
If we are going to update the global anyway why change this function?
| """ | ||
| program= ( | ||
| "import matplotlib; " | ||
| "import matplotlib.cm as cm; " |
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.
This import order currently works, can you explain a bit more exactly what this is testing?matplotlib.cm is imported inmatplotilb/__init__.py so this import never actually triggers the import.
| # Run submodule initialization after rcParams are loaded | ||
| _run_submodule_inits() |
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.
might as well put this almost at the bottom? The thing in particular that gets us in trouble is that if we access an attribute onmatplotlib in a sub-module before we have created it.rcParams is the most common problem (and the problem here) but we should cover the (more) general case and put this call as late as possible.
| _bivar_colormaps=ColormapRegistry(bivar_cmaps) | ||
| def_ensure_cmap(cmap): |
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.
Why was this added?
PR summary
Implementing the mpl_init mechanism to avoid dependency, as described in the discussion of issue#29813. Additionally, some tests are implemented.
Is a documentation update necessary?