• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aymgal / COOLEST / 4244003410

pending completion
4244003410

Pull #30

github

GitHub
Merge 8f5dfabb6 into 455fe61b5
Pull Request #30: Initial steps towards a plotting API

433 of 433 new or added lines in 11 files covered. (100.0%)

813 of 1609 relevant lines covered (50.53%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/coolest/api/plot_util.py
1
__author__ = 'aymgal'
×
2

3

4
import numpy as np
×
5
import warnings
×
6
import matplotlib.pyplot as plt
×
7
from matplotlib import ticker
×
8
from mpl_toolkits.axes_grid1 import make_axes_locatable
×
9

10

11
def std_colorbar(mappable, label=None, fontsize=12, label_kwargs={}, **colorbar_kwargs):
×
12
    cb = plt.colorbar(mappable, **colorbar_kwargs)
×
13
    if label is not None:
×
14
        colorbar_kwargs.pop('label', None)
×
15
        cb.set_label(label, fontsize=fontsize, **label_kwargs)
×
16
    return cb
×
17

18
def std_colorbar_residuals(mappable, res_map, vmin, vmax, label=None, fontsize=12, 
×
19
                           label_kwargs={}, **colorbar_kwargs):
20
    if res_map.min() < vmin and res_map.max() > vmax:
×
21
        cb_extend = 'both'
×
22
    elif res_map.min() < vmin:
×
23
        cb_extend = 'min'
×
24
    elif res_map.max() > vmax:
×
25
        cb_extend = 'max'
×
26
    else:
27
        cb_extend = 'neither'
×
28
    colorbar_kwargs.update({'extend': cb_extend})
×
29
    return std_colorbar(mappable, label=label, fontsize=fontsize, 
×
30
                        label_kwargs=label_kwargs, **colorbar_kwargs)
31

32
def nice_colorbar(mappable, position='right', pad=0.1, size='5%', label=None, fontsize=12, 
×
33
                  invisible=False, max_nbins=None,
34
                  divider_kwargs={}, colorbar_kwargs={}, label_kwargs={}):
35
    divider_kwargs.update({'position': position, 'pad': pad, 'size': size})
×
36
    ax = mappable.axes
×
37
    divider = make_axes_locatable(ax)
×
38
    cax = divider.append_axes(**divider_kwargs)
×
39
    if invisible:
×
40
        cax.axis('off')
×
41
        return None
×
42
    cb = plt.colorbar(mappable, cax=cax, **colorbar_kwargs)
×
43
    if label is not None:
×
44
        colorbar_kwargs.pop('label', None)
×
45
        cb.set_label(label, fontsize=fontsize, **label_kwargs)
×
46
    if position == 'top':
×
47
        cax.xaxis.set_ticks_position('top')
×
48
    if max_nbins is not None:
×
49
        cb.locator = ticker.MaxNLocator(nbins=max_nbins)
×
50
        cb.update_ticks()
×
51
    return cb
×
52

53
def nice_colorbar_residuals(mappable, res_map, vmin, vmax, position='right', pad=0.1, size='5%', 
×
54
                            invisible=False, label=None, fontsize=12,
55
                            divider_kwargs={}, colorbar_kwargs={}, label_kwargs={}):
56
    if res_map.min() < vmin and res_map.max() > vmax:
×
57
        cb_extend = 'both'
×
58
    elif res_map.min() < vmin:
×
59
        cb_extend = 'min'
×
60
    elif res_map.max() > vmax:
×
61
        cb_extend = 'max'
×
62
    else:
63
        cb_extend = 'neither'
×
64
    colorbar_kwargs.update({'extend': cb_extend})
×
65
    return nice_colorbar(mappable, position=position, pad=pad, size=size, label=label, fontsize=fontsize,
×
66
                  invisible=invisible, colorbar_kwargs=colorbar_kwargs, label_kwargs=label_kwargs,
67
                  divider_kwargs=divider_kwargs)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc