|
9 | 9 | module is imported, register them here rather then in the module.
|
10 | 10 |
|
11 | 11 | """
|
| 12 | +import importlib |
| 13 | + |
12 | 14 | import pandas._config.config as cf
|
13 | 15 | from pandas._config.config import (
|
14 | 16 | is_bool, is_callable, is_instance_factory, is_int, is_one_of_factory,
|
@@ -460,6 +462,40 @@ def use_inf_as_na_cb(key):
|
460 | 462 | # Plotting
|
461 | 463 | # ---------
|
462 | 464 |
|
| 465 | +plotting_backend_doc = """ |
| 466 | +: str |
| 467 | + The plotting backend to use. The default value is "matplotlib", the |
| 468 | + backend provided with pandas. Other backends can be specified by |
| 469 | + prodiving the name of the module that implements the backend. |
| 470 | +""" |
| 471 | + |
| 472 | + |
| 473 | +def register_plotting_backend_cb(key): |
| 474 | + backend_str = cf.get_option(key) |
| 475 | + if backend_str == 'matplotlib': |
| 476 | + try: |
| 477 | + import pandas.plotting._matplotlib # noqa |
| 478 | + except ImportError: |
| 479 | + raise ImportError('matplotlib is required for plotting when the ' |
| 480 | + 'default backend "matplotlib" is selected.') |
| 481 | + else: |
| 482 | + return |
| 483 | + |
| 484 | + try: |
| 485 | + importlib.import_module(backend_str) |
| 486 | + except ImportError: |
| 487 | + raise ValueError('"{}" does not seem to be an installed module. ' |
| 488 | + 'A pandas plotting backend must be a module that ' |
| 489 | + 'can be imported'.format(backend_str)) |
| 490 | + |
| 491 | + |
| 492 | +with cf.config_prefix('plotting'): |
| 493 | + cf.register_option('backend', defval='matplotlib', |
| 494 | + doc=plotting_backend_doc, |
| 495 | + validator=str, |
| 496 | + cb=register_plotting_backend_cb) |
| 497 | + |
| 498 | + |
463 | 499 | register_converter_doc = """
|
464 | 500 | : bool
|
465 | 501 | Whether to register converters with matplotlib's units registry for
|
|
0 commit comments