Creates figures and switches between figures. If a ``bqplot.Figure`` object is provided via the fig optional argument, this figure becomes the current context figure. Otherwise: - If no key is provided, a new empty context figure is created. - If a key is provided for which a
(key=None, fig=None, **kwargs)
| 119 | |
| 120 | |
| 121 | def figure(key=None, fig=None, **kwargs): |
| 122 | """Creates figures and switches between figures. |
| 123 | |
| 124 | If a ``bqplot.Figure`` object is provided via the fig optional argument, |
| 125 | this figure becomes the current context figure. |
| 126 | |
| 127 | Otherwise: |
| 128 | |
| 129 | - If no key is provided, a new empty context figure is created. |
| 130 | - If a key is provided for which a context already exists, the |
| 131 | corresponding context becomes current. |
| 132 | - If a key is provided and no corresponding context exists, a new context |
| 133 | is reated for that key and becomes current. |
| 134 | |
| 135 | Besides, optional arguments allow to set or modify Attributes |
| 136 | of the selected context figure. |
| 137 | |
| 138 | Parameters |
| 139 | ---------- |
| 140 | key: hashable, optional |
| 141 | Any variable that can be used as a key for a dictionary |
| 142 | fig: Figure, optional |
| 143 | A bqplot Figure |
| 144 | |
| 145 | """ |
| 146 | scales_arg = kwargs.pop('scales', {}) |
| 147 | _context['current_key'] = key |
| 148 | if fig is not None: # fig provided |
| 149 | _context['figure'] = fig |
| 150 | if key is not None: |
| 151 | _context['figure_registry'][key] = fig |
| 152 | for arg in kwargs: |
| 153 | setattr(_context['figure'], arg, kwargs[arg]) |
| 154 | else: # no fig provided |
| 155 | if key is None: # no key provided |
| 156 | _context['figure'] = Figure(**kwargs) |
| 157 | else: # a key is provided |
| 158 | if key not in _context['figure_registry']: |
| 159 | if 'title' not in kwargs: |
| 160 | kwargs['title'] = 'Figure' + ' ' + str(key) |
| 161 | _context['figure_registry'][key] = Figure(**kwargs) |
| 162 | _context['figure'] = _context['figure_registry'][key] |
| 163 | for arg in kwargs: |
| 164 | setattr(_context['figure'], arg, kwargs[arg]) |
| 165 | scales(key, scales=scales_arg) |
| 166 | # Set the axis reference dictionary. This dictionary contains the mapping |
| 167 | # from the possible dimensions in the figure to the list of scales with |
| 168 | # respect to which axes have been drawn for this figure. |
| 169 | # Used to automatically generate axis. |
| 170 | if getattr(_context['figure'], 'axis_registry', None) is None: |
| 171 | setattr(_context['figure'], 'axis_registry', {}) |
| 172 | return _context['figure'] |
| 173 | |
| 174 | |
| 175 | def close(key): |
no test coverage detected
searching dependent graphs…