Draw colorbar(s) for applicable layer(s) Parameters ---------- location : {'left', 'right', 'top', 'bottom'}, optional The location, relative to the surface plot. If location is 'top' or 'bottom', then colorbars are horizontal. If location is'left'
(self, location='bottom', label_direction=None,
n_ticks=3, decimals=2, fontsize=10, draw_border=True,
outer_labels_only=False, aspect=20, pad=.08, shrink=.3,
fraction=.05)
| 407 | return_plotter=True, offscreen=offscreen) |
| 408 | |
| 409 | def _add_colorbars(self, location='bottom', label_direction=None, |
| 410 | n_ticks=3, decimals=2, fontsize=10, draw_border=True, |
| 411 | outer_labels_only=False, aspect=20, pad=.08, shrink=.3, |
| 412 | fraction=.05): |
| 413 | """Draw colorbar(s) for applicable layer(s) |
| 414 | |
| 415 | Parameters |
| 416 | ---------- |
| 417 | location : {'left', 'right', 'top', 'bottom'}, optional |
| 418 | The location, relative to the surface plot. If location is 'top' or |
| 419 | 'bottom', then colorbars are horizontal. If location is'left' or |
| 420 | 'right', then colorbars are vertical. |
| 421 | label_direction : int or None, optional |
| 422 | Angle to draw label for colorbars, if provided. Horizontal = 0, |
| 423 | vertical = 90. If None and `location` is 'top' or 'bottom', labels |
| 424 | are drawn horizontally. If None and `location` is 'left' or |
| 425 | 'right', labels are drawn vertically. Default: None |
| 426 | n_ticks : int, optional |
| 427 | Number of ticks to include on colorbar, default: 3 (minimum, |
| 428 | maximum, and middle values) |
| 429 | decimals : int, optional |
| 430 | Number of decimals to show for colorbal tick values. Set 0 to show |
| 431 | integers. Default: 2 |
| 432 | fontsize : int, optional |
| 433 | Font size for colorbar labels and tick labels. Default: 10 |
| 434 | draw_border : bool, optional |
| 435 | Draw ticks and black border around colorbar. Default: True |
| 436 | outer_labels_only : bool, optional |
| 437 | Show tick labels for only the outermost colorbar. This cleans up |
| 438 | tick labels when all colorbars are the same scale. Default: False |
| 439 | pad : float, optional |
| 440 | Space that separates each colorbar. Default: .08 |
| 441 | aspect : float, optional |
| 442 | Ratio of long to short dimensions. Default: 20 |
| 443 | shrink : float, optional |
| 444 | Fraction by which to multiply the size of the colorbar. |
| 445 | Default: .3 |
| 446 | fraction : float, optional |
| 447 | Fraction of original axes to use for colorbar. Default: .05 |
| 448 | """ |
| 449 | cbar_pads = [.01] + [pad] * (len(self._show_cbar) - 1) |
| 450 | cbar_indices = [i for i, c in enumerate(self._show_cbar) if c] |
| 451 | |
| 452 | # draw in reverse order so that outermost colorbar is uppermost layer |
| 453 | for i in cbar_indices[::-1]: |
| 454 | vmin, vmax = self.color_ranges[i] |
| 455 | |
| 456 | norm = mpl.colors.Normalize(vmin, vmax) |
| 457 | sm = plt.cm.ScalarMappable(cmap=self.cmaps[i], norm=norm) |
| 458 | sm.set_array([]) |
| 459 | ticks = np.linspace(vmin, vmax, n_ticks) |
| 460 | |
| 461 | cb = plt.colorbar(sm, ticks=ticks, location=location, |
| 462 | fraction=fraction, pad=cbar_pads[i], |
| 463 | shrink=shrink, aspect=aspect, ax=plt.gca()) |
| 464 | |
| 465 | tick_labels = np.linspace(vmin, vmax, n_ticks) |
| 466 | if decimals > 0: |
no test coverage detected