|
| 1 | +import seaborn as sns |
| 2 | +import random |
| 3 | + |
| 4 | + |
| 5 | +def nhsd_colours(): |
| 6 | + '''Returns a dictionary full of the different official NHSD colours from the |
| 7 | + style guide: |
| 8 | + https://digital.nhs.uk/about-nhs-digital/corporate-information-and-documents/nhs-digital-style-guidelines/how-we-look/colour-palette |
| 9 | +
|
| 10 | + Parameters |
| 11 | + ---------- |
| 12 | + None |
| 13 | +
|
| 14 | + Returns |
| 15 | + -------- |
| 16 | + colour_dict : dict (Python dictionary) |
| 17 | + A dictionary containing sets of official NHS Digital branding colours |
| 18 | + (Hexidecimal format) and fonts. |
| 19 | + ''' |
| 20 | + |
| 21 | + nhsd_chart_colours = ['#005EB8', '#71CCEF', '#84919C', |
| 22 | + '#003087', '#D0D5D6', ] |
| 23 | + nhsd_chart_background = {'chart_grey_3': '#F8F8F8', 'white': '#FFFFFF'} |
| 24 | + nhsd_core_colours = {'white': '#ffffff', |
| 25 | + 'white_tints': ['#f9fafb', '#f3f5f6', '#edeff1', |
| 26 | + '#def2e5'], |
| 27 | + 'nhs_blue': '#005eb8', |
| 28 | + 'blue_tints': ['#337EC6', '#ACCAE8', '#D4E4F3', |
| 29 | + '#E6EFF8'], |
| 30 | + 'nhs_dark_grey': '#425563', |
| 31 | + 'grey_tints': ['#687784', '#98A4AD', '#B3BBC1', |
| 32 | + '#DFE2E5', '#EDEFF1', '#F3F5F6', |
| 33 | + '#F9FAFB'], |
| 34 | + 'nhs_mild_grey': '#768692', |
| 35 | + 'nhs_warm_yellow': '#FFB81C', |
| 36 | + 'warm_yellow_tints': ['#FFE8B4', '#FFF1CC', '#FFF8E8'] |
| 37 | + } |
| 38 | + nhsd_font = ['Frutiger Light', 'Frutiger Roman'] |
| 39 | + nhsd_font_backup = ['Arial'] |
| 40 | + colour_dict = {'chart': nhsd_chart_colours, |
| 41 | + 'chart_background': nhsd_chart_background, |
| 42 | + 'core': nhsd_core_colours, |
| 43 | + 'font': nhsd_font, |
| 44 | + 'font_backup': nhsd_font_backup} |
| 45 | + return colour_dict |
| 46 | + |
| 47 | + |
| 48 | +def nhsd_seaborn_style(): |
| 49 | + '''Sets the seaborn style to be inline with NHSD guidlines. This means your |
| 50 | + graphs in Seaborn, or in Matplotlib will come out looking as per the NHSD |
| 51 | + style guide. Simply run this function. |
| 52 | +
|
| 53 | + Parameters |
| 54 | + ---------- |
| 55 | + None |
| 56 | +
|
| 57 | + Returns |
| 58 | + ---------- |
| 59 | + None''' |
| 60 | + nhs_colours = nhsd_colours() |
| 61 | + chart_background = nhs_colours['chart_background'] |
| 62 | + font_backup = nhs_colours['font_backup'] |
| 63 | + chart_colours = nhs_colours['chart'] |
| 64 | + |
| 65 | + additional_colours = (nhsd_colours()['core']['blue_tints'] + |
| 66 | + nhsd_colours()['core']['grey_tints'] + |
| 67 | + nhsd_colours()['core']['nhs_warm_yellow'] + |
| 68 | + nhsd_colours()['core']['warm_yellow_tints']) |
| 69 | + random.shuffle(additional_colours) |
| 70 | + nhs_colours = chart_colours + additional_colours |
| 71 | + |
| 72 | + sns.set_palette(nhs_colours) |
| 73 | + |
| 74 | + seaborn_style_dict = {'axes.axisbelow': True, |
| 75 | + 'axes.edgecolor': '.8', |
| 76 | + 'axes.facecolor': chart_background['chart_grey_3'], |
| 77 | + 'axes.grid': True, |
| 78 | + 'axes.labelcolor': '.15', |
| 79 | + 'axes.spines.bottom': False, # no spines |
| 80 | + 'axes.spines.left': False, # no spines |
| 81 | + 'axes.spines.right': False, # no spines |
| 82 | + 'axes.spines.top': False, # no spines |
| 83 | + 'figure.facecolor': chart_background['chart_grey_3'], |
| 84 | + 'font.family': ['sans-serif'], |
| 85 | + 'font.sans-serif': font_backup, |
| 86 | + 'grid.color': '.8', |
| 87 | + 'grid.linestyle': '-', |
| 88 | + 'image.cmap': 'rocket', |
| 89 | + 'lines.solid_capstyle': 'round', |
| 90 | + 'patch.edgecolor': 'w', |
| 91 | + 'patch.force_edgecolor': True, |
| 92 | + 'text.color': '.15', |
| 93 | + 'xtick.bottom': False, |
| 94 | + 'xtick.color': '.15', |
| 95 | + 'xtick.direction': 'out', |
| 96 | + 'xtick.top': False, |
| 97 | + 'ytick.color': '.15', |
| 98 | + 'ytick.direction': 'out', |
| 99 | + 'ytick.left': False, |
| 100 | + 'ytick.right': False} |
| 101 | + sns.set_style('whitegrid', seaborn_style_dict) |
0 commit comments