Draws axes corresponding to the scales of a given mark. It also returns a dictionary of drawn axes. If the mark is not provided, the last drawn mark is used. Parameters ---------- mark: Mark or None (default: None) The mark to inspect to create axes. If None, the last m
(mark=None, options={}, **kwargs)
| 311 | |
| 312 | |
| 313 | def axes(mark=None, options={}, **kwargs): |
| 314 | """Draws axes corresponding to the scales of a given mark. |
| 315 | |
| 316 | It also returns a dictionary of drawn axes. If the mark is not provided, |
| 317 | the last drawn mark is used. |
| 318 | |
| 319 | Parameters |
| 320 | ---------- |
| 321 | mark: Mark or None (default: None) |
| 322 | The mark to inspect to create axes. If None, the last mark drawn is |
| 323 | used instead. |
| 324 | options: dict (default: {}) |
| 325 | Options for the axes to be created. If a scale labeled 'x' is required |
| 326 | for that mark, options['x'] contains optional keyword arguments for the |
| 327 | constructor of the corresponding axis type. |
| 328 | """ |
| 329 | if mark is None: |
| 330 | mark = _context['last_mark'] |
| 331 | if mark is None: |
| 332 | return {} |
| 333 | fig = kwargs.get('figure', current_figure()) |
| 334 | scales = mark.scales |
| 335 | fig_axes = [axis for axis in fig.axes] |
| 336 | axes = {} |
| 337 | for name in scales: |
| 338 | if name not in mark.class_trait_names(scaled=True): |
| 339 | # The scale is not needed. |
| 340 | continue |
| 341 | scale_metadata = mark.scales_metadata.get(name, {}) |
| 342 | dimension = scale_metadata.get('dimension', scales[name]) |
| 343 | axis_args = dict(scale_metadata, |
| 344 | **(options.get(name, {}))) |
| 345 | |
| 346 | axis = _fetch_axis(fig, dimension, scales[name]) |
| 347 | if axis is not None: |
| 348 | # For this figure, an axis exists for the scale in the given |
| 349 | # dimension. Apply the properties and return back the object. |
| 350 | _apply_properties(axis, options.get(name, {})) |
| 351 | axes[name] = axis |
| 352 | continue |
| 353 | |
| 354 | # An axis must be created. We fetch the type from the registry |
| 355 | # the key being provided in the scaled attribute decoration |
| 356 | key = mark.class_traits()[name].get_metadata('atype') |
| 357 | if key is not None: |
| 358 | axis_type = Axis.axis_types[key] |
| 359 | axis = axis_type(scale=scales[name], **axis_args) |
| 360 | axes[name] = axis |
| 361 | fig_axes.append(axis) |
| 362 | # Update the axis registry of the figure once the axis is added |
| 363 | _update_fig_axis_registry(fig, dimension, scales[name], axis) |
| 364 | fig.axes = fig_axes |
| 365 | return axes |
| 366 | |
| 367 | |
| 368 | def _set_label(label, mark, dim, **kwargs): |
no test coverage detected
searching dependent graphs…